问题描述
我知道Thread.Suspend()和Thread.Resume()不适合程序实践。
我已经构建了一个小的Windows窗体应用程序。
当用户在处理任务时关闭窗口窗体时,我显示警告消息框(FormClosing事件)。如果用户单击是按钮,则它将退出应用程序。如果他们单击否,则它将执行操作。
即使出现警告消息框,应用程序也会执行该任务。但我想如果出现警告消息框,那么我必须暂停线程。如果用户点击是按钮,那么我将终止。如果用户点击否,那么我将继续这个过程。
请指导我。 。 。 ,
I know Thread.Suspend() and Thread.Resume() is not good one for program practice.
I have built one small windows form application.
When user close the Window Form while processing the task, i'm showing warning message box(FormClosing Event). If user clicks "yes" button then it will Exit the application. If they click "No" then it will perform the action.
Even though warning Message Box appears, application performing the task. But i want if the warning message box appears then i must pause the thread. If user clicked "yes" button then i'll terminate. If user clicked "No" then i'll continue the process.
Please guide me on this. . . ,
private void frmTranxitCCTVJobCreation_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
if (bIsButtonClicked == true)
{
if (_threadProcessCCTV.IsAlive)
{
dynamic mboxResult = MessageBox.Show("Are you sure you want to exit the form?", "Tranxit CCTV Job Creation Tool", MessageBoxButtons.YesNo);
if (mboxResult == DialogResult.Yes)
{
//e.Cancel = false;
Application.Exit();
}
if (mboxResult == DialogResult.No)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
}
}
}
}
}
推荐答案
这篇关于如何在线程中暂停和恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!