为什么.NET不允许跨线程操作? [英] Why .NET does not allow cross-thread operations?

查看:134
本文介绍了为什么.NET不允许跨线程操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   .NET控件:为什么AREN&rsquo的;吨的所有呼叫线程安全的

这个问题不是关于什么是一个跨线程操作,以及如何避免它,但为什么.NET框架的内部机制不允许跨线程操作。

This question is not about what is a cross-thread operation, and how to avoid it, but why internal mechanics of .NET framework does not allow a cross-thread operation.

我`吨明白为什么的SerialPort DataReceived事件检索无法更新我的形式简单的文本框,以及为什么使用委托这是可能的吗?

I can`t understand why a SerialPort DataReceived event cannot update a simple text box on my form and why using delegates this is possible?

推荐答案

.NET允许跨线程操作。但是,你应该安全地处理它。使用调用 / 的BeginInvoke 的方法进行跨线程操作。调用的意思是嘿,文本框!请更新自己,当你将有时间。下面是使用对MSDN

.NET allows cross-thread operations. But you should handle it safely. Use Invoke / BeginInvoke methods for cross-thread operations. Invoke means "Hey, text box! Please update yourself when you will have time." Here is an example of usage on MSDN

这篇关于为什么.NET不允许跨线程操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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