序言
初学者遇到在非UI线程中操作控件会异常,这时会很蒙圈,包括我初学winform的时候也是一样的,闲下来没事的时候对该操作做了一个demo尝试,接下来做一个解释与记录。
解决方案
直接附上代码:
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
delegate void SetLabel(string text);
private void ChangeLabel4Text(string text)
{
label4.Text = text;
}
WindowsFormsSynchronizationContext context;
SynchronizationContext context1;
public Form1()
{
InitializeComponent()