הנה קוד לדוגמא. מה עשיתי לא בסדר?
private Thread t; public void DoStuffWithThread(int times) { _times = times; _executeThread = true; t = new Thread(new ThreadStart(threadProc)); t.Start(); } private void threadProc() { for (int i = 0; i<_times; i++) { if (!_executeThread) return; SomeThingLongToDo(); } StopThread(); } public event EventHandler ThreadIsStopped; public void StopThread() { _executeThread = true; try { if (t.IsAlive) t.Abort(); } catch { } finally { t.Join(); // Here it get stuck t = null; } ThreadIsStopped(this,EventArgs.Empty); }