473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 21 '05 #1
2 8885
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 21 '05 #2
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 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
2
by: rawCoder | last post by:
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...
0
by: Chi Tang | last post by:
Hi, When I close some windows from Visual Studio .NET I got the dialogBox shows an exception occurred which shows following text: InvalidOperationException: Cannot call Invoke or InvokeAsync...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
3
by: qfchen | last post by:
Hi, I have a problem to call a richText control's invoke from other window form while program background work. however if I implement the background work under the same window form as the control,...
0
by: shaily | last post by:
hi I have a java web service called "Registration service" and C# client which is a consumer of that service java web service running under Tomcat has following interface API exposed ...
2
by: LVP | last post by:
Hello, How does Control.Invoke(delegate) work? Executes the specified delegate on the thread that owns the control's underlying window handle I am looking for Underthehood explanation. How...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.