C# cancelling DoWork of background worker

前端 未结 4 1840
春和景丽
春和景丽 2021-02-06 15:50

C# 2008

I am using the code below to login to a softphone. However, the login progess is a long process as there are many things that have to be initialized and checks t

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 16:26

    You are doing it the right way, I believe. You will find thread members that allow you to terminate or abort a thread, but you don't want to use them for something like this. It might look a little weird to have all of the "cancelled" checks in your code, but that allows you to control exactly when you exit your thread. If you were to "rudely" abort the worker thread, the thread has no control of when it exits, and there could be corrupted state.

提交回复
热议问题