C# Winform通过SynchronizationContext(提供在各种同步模型中传播同步上下文的基本功能)加载信息

        private SynchronizationContext _ThreadSync = null;
        //Show Message At ListView
        private void AddMessage(object str_msg)
        {
            txtBoxInfo.Text += Environment.NewLine + str_msg.ToString();
        }
        private void btnPrintCaton_Click(object sender, EventArgs e)
        {
            string strlocation = TxtBoxCaton.Text.Trim();
            if (String.IsNullOrEmpty(strlocation))
                _ThreadSync.Post(AddMessage, "请输入Carton...");

            PrintLabel("CARTON", strlocation);
        }    

      private void Form1_Load(object sender, EventArgs e)
      {
        _ThreadSync = SynchronizationContext.Current;
      }

 

 

posted @ 2019-10-31 11:25  吴土炮Jared  阅读(463)  评论(0编辑  收藏  举报