스레드를 만든 폼의 목록 상자로 돌아가서 별도의 클래스에서 실행되는 스레드에서 텍스트를 얻는 데 도움이되는 솔루션을 검색했지만 찾을 수 없습니다.별도의 스레드/클래스에서 컨트롤 속성 설정
기본적으로 나는 "테스트"를 보유하는 클래스를 가지고 있으며 테스트 창에서 자신의 스레드로 호출됩니다. 내가 할 수 있기를 원하는 것은 주 양식의 목록 상자에 텍스트를 추가하여 사용자가 테스트를 통해 어떤 일이 벌어지고 있는지 알 수 있도록하는 것입니다. 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);
}
}
}
내가 나를 스레드를 시작하는 버튼이 같은 폼에서 목록 상자에 다시 텍스트를 얻을하는 방법을 이해하는 데 도움이 수있는 모든 일을 감사하겠습니다
.