Structure次のコンストラクターを(パラメーターを に設定して )呼び出すたびにTrue、NullReferenceException が発生します。
Imports System.Threading
Imports System.Windows.Threading
Public Structure Test
Private MyDispatcher As Dispatcher
Private MyResetEvent As ManualResetEvent
Public Sub New(ByVal newThread As Boolean)
If newThread Then
MyResetEvent = New ManualResetEvent(False)
Dim thread As New Thread(AddressOf Start)
thread.Start()
MyResetEvent .WaitOne()
' NullReferenceException below:
MyDispatcher.BeginInvoke(New Action(AddressOf DoSomething))
End If
End Sub
Private Sub Start()
MyDispatcher = Dispatcher.CurrentDispatcher
MyResetEvent.Set()
Dispatcher.Run()
End Sub
Private Sub DoSomething()
End Sub
End Structure
MyDispatcherでありNothing、NullReferenceException を引き起こします。ただし、 a のClass代わりに aを使用すると問題なくStructure動作します。なんで?
編集:そして、どのような回避策が可能ですか?