views:

96

answers:

3

hi,

I have an application running with the thread,if i perform end-task from the task manager application is quitting but,in process list an instance will be running(i.e if I do end-task 5 times 5 instances of process running). It might be due to thread.

in this case,if I have to kill all process i need to restart the device :-(.

Manually if I exit It works great.How to overcome from this issue?

I am developing application in c#

+1  A: 

Set IsBackground property on your thread to true.

elder_george
+4  A: 

As elder_george points out, you have a rogue thread that is preventing the app from exiting and you need to ensure that thread exits when your app shuts down. With CF 3.5 you can usually just set the IsBackground property to truw, though that's not always enough. If the thread is blocking in a system call (like an infinite wait like WaitOne) then the thread will not get schedules and still may not terminate.

The best way to prevent this, and a good practice, is to actually write code that signals your worker threads to shut themselves down. This is often done with a reset event or a boolean flag that the thread checks periodically.

void MyThreadProc()
{
    // set this event when the app is shutting down
    while(!shutdownEvet.WaitOne(0, false))
    {
        // do my thread stuff
    }
}

This mechanism will also work in CF 2.0 (where IsBackground doesn't exist).

ctacke
ill look into this thanks
Shadow
A: 

Hey i got solution for this,

when i perform end task from task manager,control will come next to "Application.Run()" method. There we can call one user defined function, in that we can perform all the necessary task like killing thread, memory clean up etc.. to end the application smoothly.

Thanks to all for your responses.

Shadow