开发者

Application is not qutting from task manager

开发者 https://www.devze.com 2022-12-08 08:21 出处:网络
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 instanc

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#


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).


Set IsBackground property on your thread to true.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消