This question already has an answer here:
这个问题在这里已有答案:
- How do you handle a thread that has a hung call? 5 answers
- 你如何处理挂断电话的线程? 5个答案
- Abort long running thread in button click event 3 answers
- 在按钮单击事件3答案中中止长时间运行的线程
- Force Cancel Task with API that might hang 2 answers
- 使用可能挂起2个答案的API强制取消任务
I have a BackgroundWorker process created this way:
我有这样创建的BackgroundWorker流程:
_worker = new BackgroundWorker();
_worker.WorkerSupportsCancellation = true;
_worker.DoWork += WaitForCard;
_worker.RunWorkerAsync();
The worker process is calling an API for smart card (for instance it is SCardGetStatusChange function API). That call blocks execution until a card is placed on a reader.
工作进程正在调用智能卡的API(例如,它是SCardGetStatusChange函数API)。该调用会阻止执行,直到将卡放在读卡器上。
The problem is when I close the Winform application. I am using:
问题是当我关闭Winform应用程序时。我在用:
_worker.CancelAsync();
_worker.Dispose();
The worker process set its CancellationPending property to true and the main form closes, however, application does not actually exit because the worker process is still waiting for the external input.
工作进程将其CancellationPending属性设置为true并且主窗体关闭,但是,应用程序实际上不会退出,因为工作进程仍在等待外部输入。
How to finish the working process even when it is waiting for an external input?
即使在等待外部输入时如何完成工作过程?
1 个解决方案
#1
1
EDIT: To force the SCardGetStatusChange function to cancel, use SCardCancel: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379470(v=vs.85).aspx
编辑:要强制取消SCardGetStatusChange函数,请使用SCardCancel:https://msdn.microsoft.com/en-us/library/windows/desktop/aa379470(v = vs.85).aspx
#1
1
EDIT: To force the SCardGetStatusChange function to cancel, use SCardCancel: https://msdn.microsoft.com/en-us/library/windows/desktop/aa379470(v=vs.85).aspx
编辑:要强制取消SCardGetStatusChange函数,请使用SCardCancel:https://msdn.microsoft.com/en-us/library/windows/desktop/aa379470(v = vs.85).aspx