Well actually i am calling it for a form ... the code i want to run is on
form level... heres some code, hope that might help.
Lets say this is a method in event management class and is called when some
intimator wants to raise a event and pass the data to the receiver
Public Sub DataReceivedASy nchRaiser(ByVal Data As String, Optional ByVal
IsInbound As Boolean = True)
Dim del As DataReceivedDel egate
' TODO: TRICK WARNING - undocumented way to raise event by appending
event with word Event
For Each del In m_DataReceivedE vent.GetInvocat ionList()
del.BeginInvoke (Data, Nothing, Nothing)
Next
End Sub
The delegate being called is like
Public Delegate Sub DataReceivedDel egate(ByVal Data As String )
and the event is declared as
Public Event m_DataReceived As DataReceivedDel egate
now lets say that the form that wants to receive the intimation has
'Delegate Sub OnDataReceivedD elegate(ByVal data As String) '* Doesnt get
called
Delegate Sub OnDataReceivedD elegate(ByVal args() As Object)
Public Sub OnDataReceived( ByVal data As String)
Dim x As New OnDataReceivedD elegate(Address Of OnDataReceivedH andler)
Dim args() As Object = {data}
Me.Invoke(x, args) ' InvalidOpExcept ion
'Me.Invoke(x, data) '* Doesnt get called
End Sub
'Public Sub OnDataReceivedH andler(ByVal data As String) '* Doesnt get called
Public Sub OnDataReceivedH andler(ByVal args() As Object)
End Sub
Now the thing to note is that if i use the delegate that has data as
argument, nothing happens ( the control doesnt switch) on the invoke call
but when i use the args argument then that exception occurs.
The first code is from a singleton class used to raise and receive (call)
event and pass data. the second is the form which wants to receive the data.
Hope now the problem is clear. i am not sure if the code would work on empty
project as i have copied it directly from my project.
Lemme know wat mistake i am doing.
Thanx
rawCoder
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:e0******** ******@TK2MSFTN GP11.phx.gbl...
rawCoder,
I would be more inclined to believe the framework. Basically, the
handle to the control that you are calling Invoke on doesn't exist at the
time of the call. Are you doing this in the constructor, perhaps, or
somewhere else? Has the control been removed and not yet disposed?
You might be better off calling Invoke on the main form, instead of
one of the child window controls (in the end, it doesn't really matter which
control you call it on, as it will most likely all be on the same thread).
If you could post some code, it would help.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"rawCoder" <ra******@hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. Hi
I am having this InvalidOperatio nException with message Cannot call
Invoke or InvokeAsync on a control until the window handle has been created
This is raised when i try to invoke a method with arguments
I need to do this as the method is being called Asynchronously from
elsewhere using delegate's BeginInvoke method.
The form is well created/initialized yet the messages states otherwise.
Cant extract a sample code out of my app.
Let me know if the code is needed for the problem.
All controls on the form are in a panel. The form itself isnt show, but
the
panel is shown as a child control of some other panel. Can this be the
problem.
Thank you
rawCoder