thanks alot peter
I see where u are going...and i do have a boolean flag...
for telling the threads to stop...
i will work that flag into the errorhandling
the threads should not know the difference , since
if i have 4 threads running the errorhandler will set the flag once , even
though the errhandler was called 4 times
on any error each thread stops anyway...but the manager i wrote, starts a
new job for existing , non busy threads...
so just setting this flag in the errorhandler should do the trick
thanks alot
much appriciated
>> [...]
>> what i want to do is stop the threads (not destroy)
[quoted text clipped - 17 lines]
>
> Pete
Analizer1 - 02 Apr 2008 15:41 GMT
I need to Stop The Service Gracefully
ive managed to stop all the threads gracefully
but im having problems gracefully, stopping the service
small example below
the code below is not the actual code but a way to see whats going on
hope it helps
//on start of a service
public partial class Myservice //inherits in designer
{
MyThreadManager ThreadManager=null;
protected void onStart()
{
if (ThreadManager==null) // 1st call on start of service
{
ThreadManager= new MyThreadManager()
if (ThreadManager.InitThreads()==true) // read
config file, create threads 1 to many, check sql connection
{
ThreadManager.EnableTimers() // starts kicking
off Jobs
}
}
}
}
/// code in theread Manager
public Class ThreadManager
{
private ThreadWorkers[] _aThreads // inherits BackGroundWorker
private Systems.Timers.Timer[] _aTimers
private MyLogger Log;
public ThreadManager()
{
}
public InitThreads()
{
//.. read config
// set up logging
this.log = new MyLogger();
this.Log.CriticalEventHandelerDelegate+=CriticalEvent
// method of this class
//check sql connection
//create threads and initilize threads
//CreateTimers
{
public void RunJobType1() // called by timer[0]
{
this._aTimer[0].Enable=false; //below kicks off
all jobs of this jobtype
for (int x=0:x<_aThreads.Length;x++}
{
if (_aThreads[x].Jobtype=1 &&
_aThreads[x].isBusy==false
&&
this._StopRunning==False)
{
int TmpId=
this.GetNewJobId()
if (TmpId>0)
{
this._aThread[x].JobId=TmpId;
this._aThread[x].RunWorkerAsync();
}
{
{
}
//so a job has been kicked off above and down somwhere a fatal
event occurs i have a Event in the logging Class that if connection error
query error occurs when writing logs
//fires a CriticalFailure Event..
public void CriticalEvent(CriticalEventargs e)
{
// all the threads come here on critical events
lock (this)
{
if (this._StopRunning==false); // lets all threads know
not to work
{
this._StopRunning=True;
this.StopWorkers() // waits for each thread to
finish its job...the jobs dont matter if thery error or not the worker
always complets , errhandling is done in the business logic
//thread just runs
the business logic class
// once im back here...i am ready to shut down the
Service....as u see im below the service class i have a Reference to the
service class ._Service
//when i try to stop the service the executable just
hangs...
whats the best way to stop a service from this
point...or do i need to get back up to the service level
{
}
}
}
> thanks alot peter
> I see where u are going...and i do have a boolean flag...
[quoted text clipped - 36 lines]
>>
>> Pete