Dispose method not doing its job

  • Thread starter Thread starter Merlynx
  • Start date Start date
M

Merlynx

I am using TimerCallback to call a method in an activex dll repeatedly. The
TimerCallback works fines but when i exit the program, it still shows up in
the taskmgr i.e still running. So i use the Dispose method to release
resource from the thread on closing but still it doesn't work. I was
thinking whether it was the dll the culprit, which is better out process or
something else?

static System.Threading.Timer tr;

private void run(object state){
long value = test.MonitorRAS();
switch(value){
case 1:MessageBox.Show("Connected");break;
case 0:MessageBox.Show
("Disconnected");break;
}
}

private void Callback(){
TimerCallback call = new TimerCallback(run);
tr = new System.Threading.Timer
(call,null,0,20);
}
 
Please post a complete repro, the snippet you posted doesn't show the
Dispose method's implementation.
Are you running this on a separate thread? If it is, make sure it's a
backgroud thread otherwise the process will not terminate if the threadproc
is in an endless loop.

Willy.
 
The Dispose method is implemented in an event handler closing. No it is not
a background thread.
 
When I read this "the Dispose method to release resource from the thread on
closing but ", I assume you call Dispose from another thread than the Main
thread. Are you sure you return from the thread procedure after the call.
Remember non-background threads don't terminate when the main thread
terminates, this will prevent the process to terminate.

Willy.
 
Back
Top