本文整理匯總了VB.NET中System.Diagnostics.Process.EnableRaisingEvents屬性的典型用法代碼示例。如果您正苦於以下問題:VB.NET Process.EnableRaisingEvents屬性的具體用法?VB.NET Process.EnableRaisingEvents怎麽用?VB.NET Process.EnableRaisingEvents使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.EnableRaisingEvents屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: PrintProcessClass
' 導入命名空間
Imports System.Diagnostics
Class PrintProcessClass
Private WithEvents myProcess As Process
Private eventHandled As TaskCompletionSource(Of Boolean)
' Print a file with any known extension.
Async Function PrintDoc(ByVal fileName As String) As Task
eventHandled = New TaskCompletionSource(Of Boolean)()
myProcess = New Process
Using myProcess
Try
' Start a process to print a file and raise an event when done.
myProcess.StartInfo.FileName = fileName
myProcess.StartInfo.Verb = "Print"
myProcess.StartInfo.CreateNoWindow = True
myProcess.EnableRaisingEvents = True
AddHandler myProcess.Exited, New EventHandler(AddressOf myProcess_Exited)
myProcess.Start()
Catch ex As Exception
Console.WriteLine("An error occurred trying to print ""{0}"":" &
vbCrLf & ex.Message, fileName)
Return
End Try
' Wait for Exited event, but not more than 30 seconds.
Await Task.WhenAny(eventHandled.Task, Task.Delay(30000))
End Using
End Function
' Handle Exited event and display process information.
Private Sub myProcess_Exited(ByVal sender As Object,
ByVal e As System.EventArgs)
Console.WriteLine("Exit time: {0}" & vbCrLf &
"Exit code: {1}" & vbCrLf & "Elapsed time: {2}",
myProcess.ExitTime, myProcess.ExitCode,
Math.Round((myProcess.ExitTime - myProcess.StartTime).TotalMilliseconds))
eventHandled.TrySetResult(True)
End Sub
Shared Sub Main(ByVal args As String())
' Verify that an argument has been entered.
If args.Length <= 0 Then
Console.WriteLine("Enter a file name.")
Return
End If
' Create the process and print the document.
Dim myPrintProcess As New PrintProcessClass
myPrintProcess.PrintDoc(args(0)).Wait()
End Sub
End Class