Event and delegate from C# to VB.NET
-
Hi, i have below short code in C# public delegate void MsgEventHandler(object sender, ChatEventArgs e); public static event MsgEventHandler ChatEvent; private void Message(ChatEventArgs e) { MsgEventHandler temp = ChatEvent; if (temp != null) { foreach (MsgEventHandler handler in temp.GetInvocationList()) { handler.BeginInvoke(this, e, new AsyncCallback(EndAsync), null); } } } and when we translate in vb.NET Public Delegate Sub MsgEventHandler(ByVal sender As Object, ByVal e As ChatEventArgs) Public Shared Event ChatEvent As MsgEventHandler Private Sub EmergencyMessage(ByVal e As ChatEventArgs) Dim temp As MsgEventHandler = ChatEvent If temp <> Nothing Then For Each handler As MsgEventHandler In temp.GetInvocationList() handler.BeginInvoke(Me, e, New AsyncCallback(AddressOf EndAsync), Nothing) Next End If End Sub but i have error, Saying ChatEvent is an event and can not be called directly.Use a 'Raise Event' statement to raise an event. can u help me to figure it out from c# to vb.net? thank you regards Sri
-
Hi, i have below short code in C# public delegate void MsgEventHandler(object sender, ChatEventArgs e); public static event MsgEventHandler ChatEvent; private void Message(ChatEventArgs e) { MsgEventHandler temp = ChatEvent; if (temp != null) { foreach (MsgEventHandler handler in temp.GetInvocationList()) { handler.BeginInvoke(this, e, new AsyncCallback(EndAsync), null); } } } and when we translate in vb.NET Public Delegate Sub MsgEventHandler(ByVal sender As Object, ByVal e As ChatEventArgs) Public Shared Event ChatEvent As MsgEventHandler Private Sub EmergencyMessage(ByVal e As ChatEventArgs) Dim temp As MsgEventHandler = ChatEvent If temp <> Nothing Then For Each handler As MsgEventHandler In temp.GetInvocationList() handler.BeginInvoke(Me, e, New AsyncCallback(AddressOf EndAsync), Nothing) Next End If End Sub but i have error, Saying ChatEvent is an event and can not be called directly.Use a 'Raise Event' statement to raise an event. can u help me to figure it out from c# to vb.net? thank you regards Sri
I think if you google Raise Event, you'll see the correct syntax.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hi, i have below short code in C# public delegate void MsgEventHandler(object sender, ChatEventArgs e); public static event MsgEventHandler ChatEvent; private void Message(ChatEventArgs e) { MsgEventHandler temp = ChatEvent; if (temp != null) { foreach (MsgEventHandler handler in temp.GetInvocationList()) { handler.BeginInvoke(this, e, new AsyncCallback(EndAsync), null); } } } and when we translate in vb.NET Public Delegate Sub MsgEventHandler(ByVal sender As Object, ByVal e As ChatEventArgs) Public Shared Event ChatEvent As MsgEventHandler Private Sub EmergencyMessage(ByVal e As ChatEventArgs) Dim temp As MsgEventHandler = ChatEvent If temp <> Nothing Then For Each handler As MsgEventHandler In temp.GetInvocationList() handler.BeginInvoke(Me, e, New AsyncCallback(AddressOf EndAsync), Nothing) Next End If End Sub but i have error, Saying ChatEvent is an event and can not be called directly.Use a 'Raise Event' statement to raise an event. can u help me to figure it out from c# to vb.net? thank you regards Sri
Two ways to get the correct syntax. 1 - Read the documentation or search with the error message. 2 - Compile your C# application, open the assembly using reflector and change language to VB.NET. :)
Navaneeth How to use google | Ask smart questions
-
Two ways to get the correct syntax. 1 - Read the documentation or search with the error message. 2 - Compile your C# application, open the assembly using reflector and change language to VB.NET. :)
Navaneeth How to use google | Ask smart questions