Terminating execution

  • Thread starter Thread starter Jon Vaughan
  • Start date Start date
J

Jon Vaughan

Hi,

Im fairly new to cf.net - I have some code which is executing , but when the
thread entry form is cloed it doesnt terminate the application ( as would
running the framework ), as its still running in memory. Is this normal ?
and if it is how do i terminate the code ?

Thanks

Jon
 
Since .NETCF v1.0 provides neither IsBackground or Thread.Abort you have to
instead implement your own way to signal to a thread to stop. Commonly you
do this with a boolean, for example keepprocessing = true which you can set
from your main app when you want your thread to quit ( keepprocessing =
false). Then within your thread (assuming your code is in a loop) you loop
on
while(keepprocessing)
{
}

Alternatively if your background thread is waiting on a system handle, you
can create your own event handle, and use WaitForMultipleObjects on this and
your system handle. Then from your main code you set set the event and your
blocking code will unblock, if it was caused by your handle you can then
break out of the code hence ending your thread. You can P/Invoke the events
related API calls easily, or just borrow the code from the SDF, in
particular the OpenNETCF.Threading.EventWaitHandle - http://vault.netcf.tv
(username guest, password guest)

Peter
 
Back
Top