vb.net流程启动&停

时间:2012-07-22 08:08:33

标签: vb.net

如何使用以下代码创建一个流程,以便我可以判断它何时启动&饰面?

提前致谢:)

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

1 个答案:

答案 0 :(得分:0)

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