E
Eric Newton
Given the following code,
Public class ProgressFormManager
Public Sub BeginInvoke(ByVal method As [Delegate], ByVal args() As Object)
Dim asyncCallback As New System.Threading.WaitCallback(method)
System.Threading.ThreadPool.QueueUserWorkItem(asyncCallback, args)
End Sub
.... [other implementation details]
End Class
[in the Form codebehind]
Private Sub Button1_Click(...
Dim pfm as new ProgressFormManager(Me) 'Me is the form to become the
owner
pfm.BeginInvoke(addressof LongMethodCallback, new object() { arg1, arg2,
arg3 })
End Sub
Private Sub LongMethodCallback(byval param as object)
Dim args() as object = DirectCast(param, object())
'do lengthy work
End Sub
since ProgressFormManager attempts to keep the form created on the same
thread as the caller and then fork a worker thread, I'm using the
QueueUserWorkItem
problem follows:
A) Vb compiler fails on in ProgressFormManager.BeginInvoke with two errors:
1) 'System.Threading.WaitCallback' is a delegate type. Delegate construction
permits only a single AddressOf expression as an argument list. Often an
AddressOf expression can be used instead of a delegate construction.
2) 'AddressOf' expression cannot be converted to 'System.Delegate' because
'System.Delegate' is not a delegate type.
any ideas?
I know in C# this wouldnt even be a problem.
Public class ProgressFormManager
Public Sub BeginInvoke(ByVal method As [Delegate], ByVal args() As Object)
Dim asyncCallback As New System.Threading.WaitCallback(method)
System.Threading.ThreadPool.QueueUserWorkItem(asyncCallback, args)
End Sub
.... [other implementation details]
End Class
[in the Form codebehind]
Private Sub Button1_Click(...
Dim pfm as new ProgressFormManager(Me) 'Me is the form to become the
owner
pfm.BeginInvoke(addressof LongMethodCallback, new object() { arg1, arg2,
arg3 })
End Sub
Private Sub LongMethodCallback(byval param as object)
Dim args() as object = DirectCast(param, object())
'do lengthy work
End Sub
since ProgressFormManager attempts to keep the form created on the same
thread as the caller and then fork a worker thread, I'm using the
QueueUserWorkItem
problem follows:
A) Vb compiler fails on in ProgressFormManager.BeginInvoke with two errors:
1) 'System.Threading.WaitCallback' is a delegate type. Delegate construction
permits only a single AddressOf expression as an argument list. Often an
AddressOf expression can be used instead of a delegate construction.
2) 'AddressOf' expression cannot be converted to 'System.Delegate' because
'System.Delegate' is not a delegate type.
any ideas?
I know in C# this wouldnt even be a problem.