|
楼主 |
发表于 2019-1-8 21:13:31
|
显示全部楼层
本帖最后由 SCREA 于 2019-1-8 21:46 编辑
async/await 异步方法编程 能搞定,
串口接收事件 中 把数据push 进list
开个线程或异步编程 pop 数据, 解析数据
- namespace TestInvoker
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Thread thread = new Thread(new ThreadStart(StartSomeWorkFromUIThread));
- thread.IsBackground = true;
- thread.Start();
- //StartSomeWorkFromUIThread();
- //label1.Text = "Set value through another thread!";
- }
- private void StartSomeWorkFromUIThread()
- {
- if (this.InvokeRequired)
- {
- BeginInvoke(new EventHandler(RunsOnWorkerThread), null);
- }
- else
- {
- RunsOnWorkerThread(this, null);
- }
- }
- private void RunsOnWorkerThread(object sender, EventArgs e)
- {
- Thread.Sleep(2000);
- label1.Text = System.DateTime.Now.ToString();
- }
- }
- }
复制代码 |
|