是否有可能杀掉的BackgroundWorker的主题?

编程入门 行业动态 更新时间:2024-10-28 01:12:36
本文介绍了是否有可能杀掉的BackgroundWorker的主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有可能杀的线程的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的主题?

本文发布于:2023-11-12 07:03:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580832.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有可能   主题   BackgroundWorker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!