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;
}