BackgroundWorker的中止 [英] Backgroundworker abort

查看:374
本文介绍了BackgroundWorker的中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近尝试,而不是用经典主题的BackgroundWorker,我意识到它是造成,至少对我来说,不是解决更多的问题。
口有一个BackgroundWorker运行同步读(在这种情况下,从的SerialPort)和被阻塞约30秒,以1代码行,然后cancellationpending不是解决办法。我看到,如果将应用程序在此点关闭(无论是与交叉按钮和Application.Exit())的过程中保持僵尸永远。

I recently tried to use backgroundworker instead of "classic" threads and I'm realizing that it's causing, at least for me, more problems than solutions. I have a backgroundworker running a synchronous read (in this case from serialPort) and getting blocked around 30 seconds in 1 code line, then cancellationpending isn't the solution. I'm seeing that if the application gets closed at this point (either with the cross button and Application.Exit()) the process keeps zombie forever.

我需要一种方法来强制终止或杀死BackgroundWorker的主题。

I need a way to force abort or to kill the backgroundworker thread.

推荐答案

我不是你要完成的非常肯定的,但也许是的 SerialPort.DataReceived 事件是一个更好的解决方案?

I'm not very sure on what you're trying to accomplish, but maybe the SerialPort.DataReceived event is a better solution?

如果你已经精通线程的使用,我没有看到在使用的BackgroundWorker点。它的设计的人谁不明白摆在首位的线程。

If you're already proficient with the usage of threads, I don't see the point in using BackgroundWorker. It's designed for people who don't understand threads in the first place.

另外,我不喜欢中止线程的想法。感觉危险的,多线程应用程序不需要任何更多的冒险。

Besides, I don't like the idea of aborting a thread. It feels dangerous, and multithreaded applications don't need any more risk taking.

这篇关于BackgroundWorker的中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆