1

如何从下面的代码中创建一个流程,以便我知道它何时开始和结束?

提前致谢 :)

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()
4

1 回答 1

0

您可能想使用线程。MSDN上有一篇有趣的文章:http: //msdn.microsoft.com/en-us/library/aa289178 (v=vs.71).aspx

于 2012-07-24T09:43:02.163 回答