J
JSheble
I have a service that upon startup it creates two threads:
this.Batch = new ServiceThread();
this.Batch.FileSpec = "2*.XML";
this.tBatch = new Thread(new ThreadStart(this.Batch.WatchDir));
this.tBatch.Start();
this.AsNeeded = new ServiceThread();
this.AsNeeded.FileSpec = "1*.XML";
this.tAsNeeded = new Thread(new ThreadStart(this.AsNeeded.WatchDir));
this.tAsNeeded.Start();
The WatchDir method of the ServiceThread object sits in a loop, processing
files as they're dropped into a folder. (I know that most people would use
some kind of file notifier, but this is the chosen method of our design
group).
When the service shuts down, I was initially aborting the threads:
this.tBatch.Abort();
this.tAsNeeded.Abort();
However, this stops the thread no matter where in the process of the
WatchDir is currently at, which means if it's processing an actual file, it
aborts before it's actually done. How can I terminate the thread only after
it's actually done processing something without jeopordizing the serive
shutdown.
The main loop of the WatchDir method is merely a boolean check:
while(this.blIsRunning)
{
// do actual stuff here
}
The blIsRunning is a private field. I tried making this a public property
of the ServieThread class, then in the shutdown setting it to false, but the
service still terminates before the current transaction is completed...
this.Batch = new ServiceThread();
this.Batch.FileSpec = "2*.XML";
this.tBatch = new Thread(new ThreadStart(this.Batch.WatchDir));
this.tBatch.Start();
this.AsNeeded = new ServiceThread();
this.AsNeeded.FileSpec = "1*.XML";
this.tAsNeeded = new Thread(new ThreadStart(this.AsNeeded.WatchDir));
this.tAsNeeded.Start();
The WatchDir method of the ServiceThread object sits in a loop, processing
files as they're dropped into a folder. (I know that most people would use
some kind of file notifier, but this is the chosen method of our design
group).
When the service shuts down, I was initially aborting the threads:
this.tBatch.Abort();
this.tAsNeeded.Abort();
However, this stops the thread no matter where in the process of the
WatchDir is currently at, which means if it's processing an actual file, it
aborts before it's actually done. How can I terminate the thread only after
it's actually done processing something without jeopordizing the serive
shutdown.
The main loop of the WatchDir method is merely a boolean check:
while(this.blIsRunning)
{
// do actual stuff here
}
The blIsRunning is a private field. I tried making this a public property
of the ServieThread class, then in the shutdown setting it to false, but the
service still terminates before the current transaction is completed...