P
Patrick McClellen
We have a Win2k box accessing the IFS to 1) list files 2) copy files
and 3) delete files. When I do the same sequence from Windows
Explorer on the Win2k box, I have no problems.
However, when I do it programmatically (C# Windows Service), it seems
that multiple jobs are being spawned on the AS/400 that never end.
The service polls every x seconds (in this case 5) for new files. It
does that by using the GetFiles method on the DirectoryInfo object.
If files exist, it then copies and deletes them.
The file manipulation logic is in a class that I dereference each
loop. I also call GC.GetTotalMemory(true) to garbage collect any
objects on each loop (not so worried about performance within a
polling loop). I also posted this on the AS/400 newsgroup.
Anyone know why 1) the windows service is causing multiple jobs and 2)
why they are not ending? Or how to force the jobs to end
(programmatically) from a C# Windows Service?
I am using a timer that gets initialized in the service constructor.
It calls a function TransferFiles
The programmatic access is very simple (error checking and such
removed):
private void TransferFiles()
{
GC.GetTotalMemory(true);
this.oFileClass = new FileClass;
this.oFileClass.ProcessSomeFiles();
}
In the FileClass class...
public void ProcessFiles()
{
// Directory object and UNC path
DirectoryInfo sourceDir = new
DirectoryInfo("SomeUNCPathToTheIFShere");
// Create array representing files in the current directory matching
filespec.
FileInfo[] sourceFiles = sourceDir.GetFiles(InboundFileSpec);
// Process each file: copy, delete
foreach (FileInfo fiTemp in sourceFiles)
doFileManip(fiTemp.Name);
private void doFileManip(string InboundFileName)
{
// Do some processing to get inbound and outbound paths
File.Copy(InboundPathAndFile, OutboundPathAndFile);
File.Delete(InboundPathAndFile);
}
I also do some impersonation to set the token correctly... done at the
beginning of TransferFiles and only done once for the life of the
service. That class implements IDisposable and I call Dispose when
the service is stopped.
and 3) delete files. When I do the same sequence from Windows
Explorer on the Win2k box, I have no problems.
However, when I do it programmatically (C# Windows Service), it seems
that multiple jobs are being spawned on the AS/400 that never end.
The service polls every x seconds (in this case 5) for new files. It
does that by using the GetFiles method on the DirectoryInfo object.
If files exist, it then copies and deletes them.
The file manipulation logic is in a class that I dereference each
loop. I also call GC.GetTotalMemory(true) to garbage collect any
objects on each loop (not so worried about performance within a
polling loop). I also posted this on the AS/400 newsgroup.
Anyone know why 1) the windows service is causing multiple jobs and 2)
why they are not ending? Or how to force the jobs to end
(programmatically) from a C# Windows Service?
I am using a timer that gets initialized in the service constructor.
It calls a function TransferFiles
The programmatic access is very simple (error checking and such
removed):
private void TransferFiles()
{
GC.GetTotalMemory(true);
this.oFileClass = new FileClass;
this.oFileClass.ProcessSomeFiles();
}
In the FileClass class...
public void ProcessFiles()
{
// Directory object and UNC path
DirectoryInfo sourceDir = new
DirectoryInfo("SomeUNCPathToTheIFShere");
// Create array representing files in the current directory matching
filespec.
FileInfo[] sourceFiles = sourceDir.GetFiles(InboundFileSpec);
// Process each file: copy, delete
foreach (FileInfo fiTemp in sourceFiles)
doFileManip(fiTemp.Name);
private void doFileManip(string InboundFileName)
{
// Do some processing to get inbound and outbound paths
File.Copy(InboundPathAndFile, OutboundPathAndFile);
File.Delete(InboundPathAndFile);
}
I also do some impersonation to set the token correctly... done at the
beginning of TransferFiles and only done once for the life of the
service. That class implements IDisposable and I call Dispose when
the service is stopped.