我搜索了並找不到解決方案,它可以幫助我將文本從運行在單獨的類中的線程返回到創建線程的窗體上的列表框。從單獨的線程/類設置控制屬性
基本上我有一個持有「測試」的類,它從測試窗口自己的線程中調用。我想要做的就是將文本添加到主窗體上的列表框中,讓用戶知道測試正在進行的是什麼。我可以在Invoke上找到的所有示例都顯示瞭如何在同一個類中執行此操作。
當我啓動線程:
PermeabilityTest Run_Test = new PermeabilityTest();
public Thread WorkerThread;
private void button2_Click(object sender, EventArgs e)
{
//enable timer for test duration display
timer1.Enabled = true;
//create and start new thread.
WorkerThread = new Thread(Run_Test.RunTest);
WorkerThread.Start();
}
這裏是我的類,它實際做的工作,我需要讓文本回一個列表框從單獨的形式。
public class PermeabilityTest
{
//volatile alerts the compiler that it will be used across threads.
private volatile bool aborted;
public void RequestStop()
{
//handle saving data file here as well.
aborted = true;
}
public void RunTest()
{
//reference the comms class so we can communicate with the machine
PMI_Software.COMMS COM = new COMMS();
//some test stuffs here
int x = 0;
while(x < 100 && !aborted)
{
System.Diagnostics.Debug.Write("Well here it is, running it's own thread." + Environment.NewLine);
COM.Pause(1);
}
}
}
我希望任何一個誰可以幫助我瞭解如何獲得一些文本回到那個具有啓動線程的按鈕相同的形式在列表框。