473,666 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: BeginInvoke problem

In the form cs:
form()
{
Thisfrm = this;
}
....
....
public delegate void delegateWriteDe tail (string str);
private void WriteDetailScre en(string str)
{
delegateWriteDe tail updateDelegate = new delegateWriteDe tail (WriteDetail );
Thisfrm.BeginIn voke (updateDelegate , new object[] {str});
}

private void WriteDetail (string str)
{
this.txtDetail. Text = str + "\r\n" + this.txtDetail. Text;
}

When I call WriteDetailScre en method that will call BeginInvoke method to let the UI thread update the screen. Something, the WriteDetailScre en method may be called by the same UI thread for the form or called by other threads. When the program is running, the screen is updated properly but I find that I sometime get the error message when call the WriteDetailScre en method. The error is below:
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created"

Why?
How to solve it?
Sep 14 '06 #1
1 1820
<<abc.com>wrote :
In the form cs:
form()
{
Thisfrm = this;
}
...
...
public delegate void delegateWriteDe tail (string str);
private void WriteDetailScre en(string str)
{
delegateWriteDe tail updateDelegate = new delegateWriteDe tail (WriteDetail );
Thisfrm.BeginIn voke (updateDelegate , new object[] {str});
}

private void WriteDetail (string str)
{
this.txtDetail. Text = str + "\r\n" + this.txtDetail. Text;
}

When I call WriteDetailScre en method that will call BeginInvoke
method to let the UI thread update the screen. Something, the
WriteDetailScre en method may be called by the same UI thread for the
form or called by other threads. When the program is running, the
screen is updated properly but I find that I sometime get the error
message when call the WriteDetailScre en method. The error is below:
"Invoke or BeginInvoke cannot be called on a control until the window
handle has been created"
That suggests that something is calling WriteDetailScre en before the
form has first been displayed. It's hard to say for sure without a
short but complete program though.

(Just a tiny point - it's worth following the naming conventions at
http://tinyurl.com/2cun - it'll be easier for others to follow your
code if they can immediately guess if something is a type etc by its
capitalization. )

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 14 '06 #2

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

Similar topics

9
7589
by: David Sworder | last post by:
Hi, I have a form that displays data (is that vague enough for you?). The data comes in on a thread-pool thread. Since the thread pool thread is not the same as the UI thread, the callback function of my form follows the standard design pattern: if(IsDisposed){ return; }
22
4055
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
5
3236
by: lltaylor | last post by:
Hello, Help, I am totally stuck, I am trying to write a sample program so I can get to grips with Asynchronous Threads etc... However I can't come up with a good workflow for my program. Any help in what I should be doing/how I should structure my application would be much appreciated. I have written a sample application which bascially searches a set
6
15150
by: Valerie Hough | last post by:
I'm not entirely sure what the difference is between these two approaches. In order to avoid reentrant code, I was using Control.BeginInvoke in my UI to cause an asynchronous activity to be done on the UI's message loop. I began to get System.ExecutionEngineException errors so (on the theory of do something different if what you're doing isn't working) I switched to using delegate.BeginInvoke with the appropriate EndInvoke and the problem...
4
2293
by: Pug Fugly | last post by:
I am unable to call the .Show() method on a form that I have passed through .BeginInvoke as the AsyncState parameter. I can get back the form correctly after the .EndInvoke is called in the callback, but the process still seems to be on a different thread even though the ..EndInvoke finished running. I get "Controls created on one thread cannot be parented to a control on a different thread." Which I know is not allowed, but I thought...
55
3299
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to call operations on Controls from a delegate, otherwise it does not work. However each time I've done an operation, I must update the progressbar and progresslabel, but this cannot be done in the delegate as it does not work.
0
1270
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot believe the difference in speed! However, the asynch operation fails sometimes, despite of the fact that it works most of the time. I am really at a loss how to fix this sporadic and erratic behavior. This is a web application developed with...
0
928
by: batista | last post by:
Hello all, Let me first explain my windows application.... I have a grid which is bound to a dataview of a dataset... Now this dataset is updated from a separate thread and therefore I've used a Custom class which is inherited by dataview...and the OnListChanged and IndexListChanged event are overridden...and in those funtions im using begininvoke to make sure that when dataset changes from separate thread the grid does'nt...
2
4416
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small or simple). I am hoping the description will generate some ideas I can check out. PROBLEM: ----------------- Switching to UI thread using Invoke(), everything seems good.
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8780
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6189
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.