为什么.NET不允许跨线程操作?

编程入门 行业动态 更新时间:2024-10-11 11:24:54
本文介绍了为什么.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不允许跨线程操作?

本文发布于:2023-11-09 04:11:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不允许   线程   操作   NET

发布评论

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

>www.elefans.com

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