本文整理汇总了VB.NET中System.Diagnostics.Process.ExitTime属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Process.ExitTime属性的具体用法?VB.NET Process.ExitTime怎么用?VB.NET Process.ExitTime使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.ExitTime属性的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