시간이 경과함에 따라 표시 할 레이블의 GUI 스레드를 업데이트하는 다른 스레드에서 실행중인 스톱워치가 있습니다. 내 프로그램이 닫히면 폼 GUI에서 this.Invoke(mydelegate);
을 호출하면 스톱워치에서 시간이 표시된 라벨을 업데이트 할 때 ObjectDisposedException
이 표시됩니다.ObjectDisposedException - GUI 스레드에서 스톱워치 실행
어떻게 이것을 ObjectDisposedException
에서 제거 할 수 있습니까?
FormClosing 이벤트에서 스톱워치를 멈추려고했으나 처리하지 못했습니다. 응용 프로그램을 닫을 때 스톱워치가 배치되고,하지만 스레드가 아직 실행하고 그것을 사용하려고하는 것 같습니다 무엇
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
stopwatch = sw;
sw.Start();
//System.Threading.Thread.Sleep(100);
System.Threading.Thread t = new System.Threading.Thread(delegate()
{
while (true)
{
TimeSpan ts = sw.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds/10);
timeElapse = elapsedTime;
UpdateLabel();
}
});
stopwatchThread = t;
t.Start();
public void UpdateLabel()
{
db = new doupdate(DoUpdateLabel);
this.Invoke(db);
}
public void DoUpdateLabel()
{
toolStripStatusLabel1.Text = timeElapse;
}
코드를 게시 할 수 있습니까? – hackerhasid