如何在 c# windows 应用程序示例中使用控制线程

我需要创建一个线程以text box每隔几毫秒根据信号输入刷新文本值。


我尝试了以下代码:


public void refreshOverview(){


   //my cases for the different signal to change the value of the text here

   //code here

    case 1:

    test.text=something

    case 2:

    test.text=something2


}


test.Invoke(() => refreshOverview());

我收到了这个错误:


无法将 lambda 表达式转换为委托


谁能给我看一个简单的代码示例,说明如何使用控制线程每隔几毫秒根据一种方法更改文本的值?


拉丁的传说
浏览 175回答 2
2回答

芜湖不芜

你可以使用 Invoke 和 delegate 来解决这个问题。            test.Invoke((MethodInvoker)delegate            {                test.Text = DateTime.Now.ToString("mm:ss");            });

慕妹3242003

只需更改为:test.Invoke(new Action(() => refreshOverview()));它会起作用
打开App,查看更多内容
随时随地看视频慕课网APP