ISynchronizeInvoke - Object reference not set to an instance

J

jherl

I am getting an "Object reference not set to an instance of an object"
when I try to execute the Invoke method. I have it set up as follows:
---
Private _syncObject As System.ComponentModel.ISynchronizeInvoke
..
..
..
Dim args(0) As Object
Dim d As New RaiseReceiveEvent(AddressOf OnReceive)
..
..
args(0) = "Test Message"
..
..
_syncObject.Invoke (d, args)
 
J

Jay B. Harlow [MVP - Outlook]

Jennifer,
You need to assign a value to your _syncObject variable. The value needs to
be of a type that supports ISynchronizeInvoke.

The only types that support ISynchronizeInvoke within the Framework inherit
from System.Windows.Forms.Control.

Normally I use the instance of my MainForm.

FWIW: You are free to implement ISynchronizeInvoke in your own classes,
however implementing ISynchronizeInvoke is a very advanced topic.

Hope this helps
Jay
 
J

jherl

Do you mean something like:

x = _syncObject(d,args)

if so, how do I define x ? If not, I guess I don't quite understand.
Thanks for your help & PATIENCE -
Jennifer
 
J

jherl

Okay, forget that last post, I obviously don't know what I am doing.
Is this where the value is set:

<System.ComponentModel.Browsable(False)> _
Public Property SyncObject() As
System.ComponentModel.ISynchronizeInvoke
Get
If _syncObject Is Nothing And Me.DesignMode Then
Dim designer As IDesignerHost =
Me.GetService(GetType(IDesignerHost))
If Not (designer Is Nothing) Then
_syncObject = designer.RootComponent
End If
End If
Return _syncObject
End Get
Set(ByVal Value As System.ComponentModel.ISynchronizeInvoke)
If Not Me.DesignMode Then
If Not (_syncObject Is Nothing) And Not (_syncObject
Is Value) Then
Throw New Exception("Property can not be set at
run-time")
Else
_syncObject = Value
End If
End If
End Set
End Property

Thanks -
Jennifer
 
J

Jay B. Harlow [MVP - Outlook]

Jennifer,
Yes that is the code that sets _syncObject, Just remember that you need to
set the SyncObject property when you instantiate the class/component/control
that it is in.

Again you would set SyncObject (which sets _syncObject) to an instance of a
Control, normally I use my MainForm.

Hope this helps
Jay
 

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