1、定义
SynchronizationContext syncContext = null;
2、注册UI线程
public Form1() { InitializeComponent(); syncContext = SynchronizationContext.Current; }
3、在子线程发送消息
syncContext.Post(SetTextSafePost, "舱单已生成");
4、定义回调,此回调可以调用UI组件
private void SetTextSafePost(object text) { msgText.AppendText(text.ToString() + "\r\n"); }