System.Threading.SynchronizationContext _syncContext;
public Form1()
{
InitializeComponent();
_syncContext = SynchronizationContext.Current;
}
private void Form1_Load(object sender, EventArgs e)
{
_initThread = new Thread(Init);
_initThread.Start();
}
private void Init()
{
_syncContext.Post(ShowErrTip, "test");
}
void ShowErrTip(object err)
{
label_ErrTip.Text = err.ToString();
}
说明:
1.如果不是在对话框初始化时调用,也可以用Send代替Post
2.Post是异步,类似于BeginInvoke;Send是同步,类似于Invoke。