C# cross-thread call problem

前端 未结 3 1471
情书的邮戳
情书的邮戳 2020-12-16 09:07

I\'m writing a form app in c# and I need to be able to change the contents of a Rich Text Box from any thread, I tried using a delegate and InvokeRe

3条回答
  •  醉梦人生
    2020-12-16 09:20

    Try this - where you call the same method if an invoke is required.

    public void UpdateSub(string message)
    {
        if (!subDisplay.subBox.InvokeRequired)
        {
            subDisplay.subBox.Text = message;
        }
        else
        {
            var d = new UpdateFormText(UpdateSub);
            Invoke(d, new object[] { message });
        }
    }
    

    Where UpdateFormText is the delegate

    public delegate void UpdateFormText(string message);
    

提交回复
热议问题