本文整理匯總了VB.NET中System.ObjectDisposedException類的典型用法代碼示例。如果您正苦於以下問題:VB.NET ObjectDisposedException類的具體用法?VB.NET ObjectDisposedException怎麽用?VB.NET ObjectDisposedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ObjectDisposedException類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: ObjectDisposedExceptionTest
' 導入命名空間
Imports System.IO
Public Class ObjectDisposedExceptionTest
Public Shared Sub Main()
Dim ms As New MemoryStream(16)
ms.Close()
Try
ms.ReadByte()
Catch e As ObjectDisposedException
Console.WriteLine("Caught: {0}", e.Message)
End Try
End Sub
End Class
示例2: Main
' 導入命名空間
Imports System.Threading
Module Example
Public Sub Main()
Dim t As New Timer(AddressOf TimerNotification, Nothing,
100, Timeout.Infinite)
Thread.Sleep(2000)
t.Dispose()
t.Change(200, 1000)
Thread.Sleep(3000)
End Sub
Private Sub TimerNotification(obj As Object)
Console.WriteLine("Timer event fired at {0:F}", Date.Now)
End Sub
End Module
輸出:
Timer event fired at Monday, July 14, 2014 11:54:08 AM Unhandled Exception: System.ObjectDisposedException: Cannot access a disposed object. at System.Threading.TimerQueueTimer.Change(UInt32 dueTime, UInt32 period) at Example.Main()