提问人: 提问时间:9/7/2021 更新时间:9/8/2021 访问量:67
按引用调用线程 (.Net)
Call thread by reference (.Net)
问:
以下不起作用,因为 Is not an 因为它接收了它的参数。这意味着以下追加以调用具有值的线程的代码不起作用。Sub(ByRef t As T) ...
Action(Of T)
ByRef
ByRef
Public Sub UseLater(Of T As Structure)(ByRef t As T, m As Mutex, callback As [Delegate]) 'Includes ByRef Consumer
m.WaitOne()
m.ReleaseMutex()
callback(t)
End Sub
''...
Dim getterLock As New Mutex()
Dim buffer As MyType = Nothing
Dim threadhelper As [Delegate] = Sub(ByRef t As MyType) ''ISSUE: Action arg cannot be ByRef
UseLater(Of MyType)(t, getterLock, Sub(ByRef t_ As MyType) buffer = t_)
End Sub
getterLock.WaitOne()
Dim getLater As New Thread(threadhelper)
getLater.Start(MyObject) ''Currently in scope object
Dim getter As [Delegate] = Function() As MyType
getterLock.ReleaseMutex()
Return buffer
End Function
''getter can be passed out of scope
如何调用带有 ?
(或者等价地从 getter 和 setter 那里获得?ByRef
Func(Of T)
Action(Of T)
ByRef
答: 暂无答案
评论
Accessor
SharedContainer(Of Accessor(Of T))
SharedContainer