如何从下面的代码中创建一个流程,以便我知道它何时开始和结束?
提前致谢 :)
Public Shared Function EmptyDirectory(ByVal mydir As String)
Try
'delete all directories
Dim myFolder As String
For Each myFolder In Directory.GetDirectories(mydir)
Directory.Delete(myFolder, True)
Next
'delete all files
Dim myFile As String
For Each myFile In Directory.GetFiles(mydir)
File.Delete(myFile)
Next
Catch Ex As Exception
'MsgBox(ex.Message)
End Try
Return False
End Function
仅供参考:这就是我认为可行的方法:
Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
myProcess.Start(EmptyDirectory(DestDir))
Dim ClearDirectoryStartDateTime As String = DateTime.Now.ToString("d") & " " & DateTime.Now.ToString("HH:mm:ss")
StatusBoxName.Items.Add(ClearDirectoryStartDateTime & " - Cleaning")
' Wait until it ends.
myProcess.WaitForExit()
' Close the process to free resources.
myProcess.Close()