使用C#.net避免使用Multiple Backgroundworker的跨线程 [英] Avoid cross Thread using Multiple Backgroundworker using C#.net

查看:94
本文介绍了使用C#.net避免使用Multiple Backgroundworker的跨线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我在我的项目中使用Multiple Backgroundworker. Backgroundworker从加载时间开始.

Hi friends,
I am using Multiple Backgroundworker in my Project. Backgroundworker starts from loading time.
How can i avoid a Cross Threading in my project?

推荐答案

您可以通过全面规划线程模型来避免这种情况.银弹,它不存在.

另外,认真考虑使用其他两种创建线程的方式:使用构造函数System.Threading.Thread.Thread和使用System.Threading.ThreadPool实例化线程,请参见:
http://msdn.microsoft.com/en-us/library/gg145014.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.threading. threadpool.aspx [ ^ ].

对于类System.ComponentModel.BackgroundWorker,我的印象是,它更多地是为简化的 ad-hoc 使用而设计的,并且更多地由不合格的开发人员使用.请参阅 http://msdn.microsoft.com/en-us/library/system.componentmodel .backgroundworker.aspx [ ^ ].

另外,请尝试避免在运行时动态创建不确定(可能很大)的线程数.这是常见的设计错误之一.大多数设计良好的应用程序都需要由应用程序的逻辑和体系结构决定的固定数量的线程.在其他合理的情况下,可以在运行时的最开始配置线程数,而在某些初始阶段完成后不会增加线程数.

最后,在一个非常复杂的设计中,您可以使用一些正式的分析方法.我知道的方法基于 Petri Net 形式主义.请参阅:
http://en.wikipedia.org/wiki/Petri_net [ http://msdn.microsoft.com/zh-cn/library /ms810303.aspx [ ^ ].

由于您的问题很模糊,我认为您不会期望得到更多建议.其他所有内容实际上取决于您未与我们共享的目标细节.

—SA
You can avoid it by planning your threading model thoroughly. There is no a silver bullet and it cannot exist.

Also, seriously consider using two other ways of creation of obtaining of thread: instantiating of them using the constructor System.Threading.Thread.Thread and using System.Threading.ThreadPool, see:
http://msdn.microsoft.com/en-us/library/gg145014.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx[^].

As to the the class System.ComponentModel.BackgroundWorker, I have the impression that it''s designed more for simplified ad-hoc uses and more often used by less qualified developers; see http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^].

Also, try to avoid dynamic creation of uncertain (possibly big) number of threads in the middle of run-time. This is one of the usual design mistakes. Most well-designed applications need fixed number of threads dictated by the logic and architecture of the application; in other reasonable cases the number of thread could be configured at the very beginning of the run time, not growing after completion of certain initial phase.

Finally, in a really complex design you can use some formal methods of analysis. The methods I know are based on Petri Net formalism. Please see:
http://en.wikipedia.org/wiki/Petri_net[^].

See also this interesting and useful Microsoft article: http://msdn.microsoft.com/en-us/library/ms810303.aspx[^].

As your question is quite vague, I don''t think you can expect many more advice. Everything else really depends on the detail of your goals you did not share with us.

—SA


这篇关于使用C#.net避免使用Multiple Backgroundworker的跨线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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