Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

winforms - How to use SerialPort in .Net by using DataReceived event?

I know the DataReceived event is fired on a background thread. How do I tell the GUI thread to show the data in the event handler?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the IsInvokeRequired and BeginInvoke methods on your form to switch control back to the UI thread.

In some cases, I've also used a timer to watch for changes in some shared data structure like a list of messages. But that works best when you've got a pretty steady stream of messages coming from some background thread.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...