By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,435 Members | 2,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,435 IT Pros & Developers. It's quick & easy.

Cannot call Invoke or InvokeAsync on a control until the window handle has been created

P: n/a
Hi

I am having this InvalidOperationException 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

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.com

"rawCoder" <ra******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

I am having this InvalidOperationException 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

Nov 16 '05 #2

P: n/a
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 DataReceivedASynchRaiser(ByVal Data As String, Optional ByVal
IsInbound As Boolean = True)

Dim del As DataReceivedDelegate

' TODO: TRICK WARNING - undocumented way to raise event by appending
event with word Event

For Each del In m_DataReceivedEvent.GetInvocationList()

del.BeginInvoke(Data, Nothing, Nothing)

Next

End Sub

The delegate being called is like
Public Delegate Sub DataReceivedDelegate(ByVal Data As String )

and the event is declared as

Public Event m_DataReceived As DataReceivedDelegate

now lets say that the form that wants to receive the intimation has

'Delegate Sub OnDataReceivedDelegate(ByVal data As String) '* Doesnt get
called

Delegate Sub OnDataReceivedDelegate(ByVal args() As Object)

Public Sub OnDataReceived(ByVal data As String)

Dim x As New OnDataReceivedDelegate(AddressOf OnDataReceivedHandler)

Dim args() As Object = {data}

Me.Invoke(x, args) ' InvalidOpException

'Me.Invoke(x, data) '* Doesnt get called

End Sub

'Public Sub OnDataReceivedHandler(ByVal data As String) '* Doesnt get called

Public Sub OnDataReceivedHandler(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.com> wrote in
message news:e0**************@TK2MSFTNGP11.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.com

"rawCoder" <ra******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi

I am having this InvalidOperationException 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


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.