translate C# from VB.NET

G

Guest

I have some problem in translate the last row of this class this class

Public Delegate Sub UIUpdate(ByVal args() As Object
Public Class Invoke

Private _control As Contro
Private _uiUpdate As UIUpdat
Private _args() As Objec

Public Sub New(ByVal c As Control
' store the control that is to run the method on its threa
_control =
End Su

Public Sub Invoke(ByVal UIDelegate As UIUpdate,
ByVal ParamArray args() As Object
' called by the client and passed the delgate that
' points to the method to ru
' as well as the argument
_args = arg
_uiUpdate = UIDelegat
_control.Invoke(New EventHandler(AddressOf _invoke)
End Su

Private Sub _invoke(ByVal sender As Object, ByVal e As EventArgs
' this is now running on the same thread as the contro
' so freely call the delegat
_uiUpdate.Invoke(_args) // <== THIS LINE IS MY PROBLEMS ================
End Su

End Clas

Can someone can help me please?

Thanks
 
A

Alex Feinman [MVP]

How did you declare Public Sub Invoke(ByVal UIDelegate As UIUpdate, ByVal
ParamArray args() As Object) in C#?
It should be:
public Invoke(UIUpdate UIDelegate, params object[] args)
 
F

Franky

I dont understand your answer.

I have a Error: "Invoke cannot be called directly on a delegate." on the
last row.

This class will be use to update the UI of a form in the Compact Framework
and pass it arguments.


Alex Feinman said:
How did you declare Public Sub Invoke(ByVal UIDelegate As UIUpdate, ByVal
ParamArray args() As Object) in C#?
It should be:
public Invoke(UIUpdate UIDelegate, params object[] args)


newMan said:
I have some problem in translate the last row of this class this class:

Public Delegate Sub UIUpdate(ByVal args() As Object)
Public Class Invoker

Private _control As Control
Private _uiUpdate As UIUpdate
Private _args() As Object

Public Sub New(ByVal c As Control)
' store the control that is to run the method on its thread
_control = c
End Sub

Public Sub Invoke(ByVal UIDelegate As UIUpdate, _
ByVal ParamArray args() As Object)
' called by the client and passed the delgate that
' points to the method to run
' as well as the arguments
_args = args
_uiUpdate = UIDelegate
_control.Invoke(New EventHandler(AddressOf _invoke))
End Sub

Private Sub _invoke(ByVal sender As Object, ByVal e As EventArgs)
' this is now running on the same thread as the control
' so freely call the delegate
_uiUpdate.Invoke(_args) // <== THIS LINE IS MY PROBLEMS =================
End Sub

End Class


Can someone can help me please?!

Thanks
 
C

Chris Tacke, eMVP

Alex is saying that you can't. You can only call Invoke on methods that
exacly follow the EventHandler method signature. "Passing" data has to be
done using a global variable.

-Chris

Franky said:
I dont understand your answer.

I have a Error: "Invoke cannot be called directly on a delegate." on the
last row.

This class will be use to update the UI of a form in the Compact Framework
and pass it arguments.


Alex Feinman said:
How did you declare Public Sub Invoke(ByVal UIDelegate As UIUpdate, ByVal
ParamArray args() As Object) in C#?
It should be:
public Invoke(UIUpdate UIDelegate, params object[] args)


newMan said:
I have some problem in translate the last row of this class this class:

Public Delegate Sub UIUpdate(ByVal args() As Object)
Public Class Invoker

Private _control As Control
Private _uiUpdate As UIUpdate
Private _args() As Object

Public Sub New(ByVal c As Control)
' store the control that is to run the method on its thread
_control = c
End Sub

Public Sub Invoke(ByVal UIDelegate As UIUpdate, _
ByVal ParamArray args() As Object)
' called by the client and passed the delgate that
' points to the method to run
' as well as the arguments
_args = args
_uiUpdate = UIDelegate
_control.Invoke(New EventHandler(AddressOf _invoke))
End Sub

Private Sub _invoke(ByVal sender As Object, ByVal e As EventArgs)
' this is now running on the same thread as the control
' so freely call the delegate
_uiUpdate.Invoke(_args) // <== THIS LINE IS MY PROBLEMS =================
End Sub

End Class


Can someone can help me please?!

Thanks
 
G

Geoff Schwab [MSFT]

Hi Franky,

Check out this FAQ item:

7.10. Can I create a custom delegate to pass to invoke?
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx#7.10


--
Geoff Schwab
Program Manager
Excell Data Corporation
http://msdn.com/mobility
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.
Franky said:
I dont understand your answer.

I have a Error: "Invoke cannot be called directly on a delegate." on the
last row.

This class will be use to update the UI of a form in the Compact Framework
and pass it arguments.


Alex Feinman said:
How did you declare Public Sub Invoke(ByVal UIDelegate As UIUpdate, ByVal
ParamArray args() As Object) in C#?
It should be:
public Invoke(UIUpdate UIDelegate, params object[] args)


newMan said:
I have some problem in translate the last row of this class this class:

Public Delegate Sub UIUpdate(ByVal args() As Object)
Public Class Invoker

Private _control As Control
Private _uiUpdate As UIUpdate
Private _args() As Object

Public Sub New(ByVal c As Control)
' store the control that is to run the method on its thread
_control = c
End Sub

Public Sub Invoke(ByVal UIDelegate As UIUpdate, _
ByVal ParamArray args() As Object)
' called by the client and passed the delgate that
' points to the method to run
' as well as the arguments
_args = args
_uiUpdate = UIDelegate
_control.Invoke(New EventHandler(AddressOf _invoke))
End Sub

Private Sub _invoke(ByVal sender As Object, ByVal e As EventArgs)
' this is now running on the same thread as the control
' so freely call the delegate
_uiUpdate.Invoke(_args) // <== THIS LINE IS MY PROBLEMS =================
End Sub

End Class


Can someone can help me please?!

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top