是否有可能杀的线程的BackgroundWorker ?
在我的的DoWork 事件,我无法检查取消标志,因为我有一个阻挡 打电话到外部COM接口或查询到数据库。 CancelAsync 不取消调用COM。
In my DoWork event, I can't check the cancellation flag, because I have a blocking call to an external COM interface or a query to a database. CancelAsync doesn't cancel the call to COM.
我怎么能做到这一点吗?任何建议将是非常美联社preciated。
How can I do it, please ? Any suggestions will be very appreciated.
在此先感谢。
推荐答案我不知道的安全的方式来终止线程。
I'm not aware of a safe way to abort a thread.
一个背景工人可以检查它是否应该取消及取消本身,而是它是否关闭查询数据库有没有什么可以做,直到它返回。
A background worker can check if it should cancel and cancel itself, but if it's off querying a database there's not much you can do until it returns.
您可以做的工作在一个线程池线程,只是放弃线程并启动另一个如果它不再需要(确保当它回来从数据库查询,它会检查是否应做什么讨厌的前取消)。当然,你需要平衡的性能和管理线程同步。如果你走这条路,你可以看看互锁静态类高效的关键部分锁定。
You can do work on a ThreadPool thread and just abandon the thread and start another if it's not needed anymore (making sure that when it comes back from a db query it checks if it should cancel before doing anything nasty). Of course you'd need to balance the performance and manage thread synchronisation. If you go down that path, you could take a look at the Interlocked static class for efficient critical section locking.
更多推荐
是否有可能杀掉的BackgroundWorker的主题?
发布评论