我有两个后台线程和一个线程来处理在我的 WinForms 应用程序上运行的最小化。当程序关闭时,我使用这种方法。
private void MyForm_Closing(object sender, FormClosingEventArgs e)
{
if(labelsUpdaterThread.IsAlive == true)
labelsUpdaterThread.Abort();
if(printNotifyThread.IsAlive == true)
printNotifyThread.Abort();
if(minimizeThread.IsAlive == true)
minimizeThread.Abort();
}
labelsUpdaterThread 和 printNotifyThread 一直在运行。正如您可能猜到的那样,MinimizeThread 仅在父窗体最小化时运行。这是我的问题:
当我在上面的方法中调用 thread.abort 方法时,我的 MdiParent 表单右上角的“X”不做任何事情。点击它没有效果。
When the thread.abort methods are NOT called in my above method, closing the MdiParent will sometimes throw exceptions because the Threads are still trying to access resources on the MdiParent that are no longer available, even though they are background threads!
I'm unsure as to why this is happening, doesn't make much sense to me. Thanks in advance for any help!