mariano_donati
Active member
- Joined
- Nov 30, 2005
- Messages
- 41
- Programming Experience
- Beginner
Hi, I got some really weird exception (not the exception by itself, but the context) other day. When my client application receives a message, it raises an event. Due to this event is generated in a background thread, I need to handle it in main form with delegates. This is what I do:
Private Sub Client_MessageReceived(....) Handles Client.MessageReceived
Dim Del As New DShowChatForm(AddressOf ShowChatForm)
Me.Invoke(Del, New Object(){'Here I pass all the arguments})
End Sub
Delegate Sub DShowChatForm('Here I pass the same arguments)
Private Sub ShowChatForm('same thing here)
'This is the sub wich actualy handles the event
End Sub
The thing is when I tried to execute Me.Invoke, It says "NullReferenceException". I've got understood that I exception only appears when you're trying to use the properties and methods of an object without making (or receiving) an explicit instance of it.
The weird thing is that I've done, since I started with this kinds of applications, like 3 or 4, and each of these applications has the same structure to handles the MEssageReceived event, and none of them gave me some kind of trouble. So, I really don't know what's wrong with it.
Is it possible that exception appears because of arguments that I pass in the Me.Invoke method?
Hope someone can help me out with this.
Thank you all very much in advance.
Regards!.
Private Sub Client_MessageReceived(....) Handles Client.MessageReceived
Dim Del As New DShowChatForm(AddressOf ShowChatForm)
Me.Invoke(Del, New Object(){'Here I pass all the arguments})
End Sub
Delegate Sub DShowChatForm('Here I pass the same arguments)
Private Sub ShowChatForm('same thing here)
'This is the sub wich actualy handles the event
End Sub
The thing is when I tried to execute Me.Invoke, It says "NullReferenceException". I've got understood that I exception only appears when you're trying to use the properties and methods of an object without making (or receiving) an explicit instance of it.
The weird thing is that I've done, since I started with this kinds of applications, like 3 or 4, and each of these applications has the same structure to handles the MEssageReceived event, and none of them gave me some kind of trouble. So, I really don't know what's wrong with it.
Is it possible that exception appears because of arguments that I pass in the Me.Invoke method?
Hope someone can help me out with this.
Thank you all very much in advance.
Regards!.