How to Kill a C# Thread?

后端 未结 4 1279
抹茶落季
抹茶落季 2021-01-13 09:56

I\'ve got a thread that goes out and looks up data on our (old) SQL server.

As data comes in, I post information to a modal dialog box - the user can\'t & should

4条回答
  •  醉梦人生
    2021-01-13 10:15

    I get the feeling that giving the Thread 1000ms to abort is simply not enough. MSDN recommends that you call Thread.Join. It would definitely be helpful to see the code that is being aborted.

    Thread.Abort

    The thread is not guaranteed to abort immediately, or at all. This situation can occur if a thread does an unbounded amount of computation in the finally blocks that are called as part of the abort procedure, thereby indefinitely delaying the abort. To wait until a thread has aborted, you can call the Join method on the thread after calling the Abort method, but there is no guarantee the wait will end.

提交回复
热议问题