3

Possible Duplicate:
.NET Controls: Why aren’t all calls thread-safe?

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.

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?

Community
  • 1
  • 1
RHaguiuda
  • 3,207
  • 9
  • 37
  • 55
  • @ChrisF: nothing "possible" about it. – Richard May 24 '10 at 11:17
  • @Richard - the comment is added automatically when the first person flags the question as a duplicate. It's replaced by an edit to the body of the question once it's actually been closed. – ChrisF May 24 '10 at 11:23
  • @ChrisF: hadn't noticed that before... (but still applies :-)) – Richard May 24 '10 at 11:39

1 Answers1

2

.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

abatishchev
  • 98,240
  • 88
  • 296
  • 433
jing
  • 1,919
  • 2
  • 20
  • 39