我有一个小的VB项目似乎工作正常,除非我在某个功能中显示任何形式。
在下面的代码中,显示了form_progress
(然后在函数中稍后隐藏),但是当执行时(所有表单都关闭),进程不会结束,并且我经常陷入调试除非我手动结束它。请注意,如果我注释掉form_progress.Show()
,则在所有表单关闭后,流程将按预期结束。
起初我专注于使用form_progress
形式的问题,但事实并非如此 - 此时我显示的任何形式都会导致此问题。没有错误被抛出,所以我迷失在哪里看。如果有人有任何建议我会批评它。感谢。
Public Sub complete_action(folder As String, rename As Boolean, include_sub_folders As Boolean)
Dim dir As DirectoryInfo ' The directory that they user selected as an object
Dim output As String ' The output to be placed in the log
' Set 'output' to be an empty string (to avoid errors)
output = ""
Try
form_progress.Show()
' Set the DirectoryInfo object from the users selected directory name
dir = New DirectoryInfo(folder)
If include_sub_folders Then
output = recursive_loop(dir, rename, output)
Else
output = loop_folder(dir, folder, rename)
End If
' Write the log file
write_text.Log_File.write_to_file(output)
form_progress.Hide()
Catch oError As Exception
functions.error_handler(oError, "Error when looping through files", "complete_action")
End Try
End Sub
答案 0 :(得分:1)
尝试使用form_progress.Close()而不是Hide()。