在我的程序(form1)中,我用Form3.ShowDialog()
. 此表单运行一个由进度条跟踪的相对较长的过程。在此表单中,有一个按钮可以取消此过程(生成 pdf 文档)并恢复该过程。
取消按钮(form3)的代码如下:
Private Sub annulerBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles annulerBtn.Click
If (MsgBox("Êtes-vous sûr de vouloir annuler? Cette reviendra toutes les modifications apportées au document", MsgBoxStyle.YesNo, "annuler l'exportation") = MsgBoxResult.Yes) Then
_cancel = True
doc.Close() 'close pdf'
fs.Close() 'close stream'
If (_done And _backup) Or (Not _done And _backup) Then
'revert file from backup if backup exists'
System.IO.File.Delete(_path)
IO.File.Copy("C:\temp\temp.pdf", _path)
IO.File.Delete("C:\temp\temp.pdf")
Else
'otherwise simply delete the new file'
System.IO.File.Delete(_path)
End If
Me.Close()
Else
'continue with the form!!'
End If
End Sub
我希望此按钮结束该过程并使用备份恢复更改。
我目前远离多线程,我使用Application.DoEvents()
进程内部继续接受用户输入。
如果用户按下是按钮,则该功能按预期工作。但是,如果用户按否,该过程将按预期继续,但随后表单将关闭!
调试表明它从不调用Me.Close()
或Form3.Close()
在用户按否之后调用。
任何有关此问题的帮助将不胜感激,谢谢!
编辑:这是调用堆栈
App58.exe!App58.Form3.Form3_FormClosing(Object sender = {App58.Form3}, System.Windows.Forms.FormClosingEventArgs e = {System.Windows.Forms.FormClosingEventArgs}) Line 432 Basic
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) + 0x77 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.CheckCloseDialog(bool closingOnly = false) + 0x8c bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop(int reason, int pvLoopData, System.Windows.Forms.NativeMethods.MSG[] msgPeeked) + 0x160 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = 4, int pvLoopData = 0) + 0x1ae bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = 4, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.Application.ModalApplicationContext}) + 0x177 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) + 0x33 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x370 bytes
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x7 bytes
App58.exe!App58.Form1.RB_pdf_Click(Object sender = {Text = "Exporter PDF"}, System.EventArgs e = {System.Windows.Forms.MouseEventArgs}) Line 1994 + 0xa bytes Basic