本文整理汇总了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()