CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com | eBook Library |
|
C-Sharp Programming Post questions, answers, and comments about C#. |
![]() |
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
#1
|
|||
|
|||
Invoke or beginInvoke cannot be called until the window handle has been created.
Hi all,
I m getting above metnioned error intermidently. Scenario: I am calling splash screen form from separate thread and then calling login screen. Find here with attached code snippet. |
#2
|
|||
|
|||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
I assume you also disabled the cross threading calls exception? Reenable it, then fix your code.
Never call winforms code from anything other than the main thread.
__________________
www.monotorrent.com For all your .NET bittorrent needs NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling. |
#3
|
||||
|
||||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
Quote:
The condition arises because of the following two parts of the code : Code:
Thread splashThread = new Thread(new ThreadStart(ShowSplash)); splashThread.Start(); // ... objfrmSplash.Invoke(d); // point A //... // This is executed in a separate thread (see above) static void ShowSplash() { objfrmSplash = new frmSplash(); objfrmSplash.ShowDialog(); } You need to synchronise the calls - i.e. you have to ensure that the form has been shown & created before you call Invoke. You can use an event to do this : Code:
class Program { static public string strCulture; static public Form objfrmSplash; static public ManualResetEvent _splashFormShown = new ManualResetEvent(false); // ... if (login.StartSession()) { Form mainApp = new frmMainApp(); _splashFormShown.WaitOne(); // wait until form has been created objfrmSplash.Invoke(d); d = null; Application.Run(mainApp); } else { _splashFormShown.WaitOne(); // wait until form has been created objfrmSplash.Invoke(d); d = null; Application.Exit(); } // .... static void ShowSplash() { objfrmSplash = new frmSplash(); objfrmSplash.Load += new EventHandler(objfrmSplashLoadedEvent); objfrmSplash.ShowDialog(); } static void objfrmSplashLoadedEvent(object sender, EventArgs args) { _splashFormShown.Set(); } In future if one thread makes assumptions about the state of another thread you HAVE to ensure this with a signal as I've shown. Otherwise you'll get intermittent errors when the assumption you have made is not true and you get a race condition. Darwen.
__________________
www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls. Last edited by darwen; October 3rd, 2008 at 07:55 AM. |
#4
|
|||
|
|||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
Follow these step to resolve the above problem
1) Restart the computer. 2) Start the SQL SERVER 2008 setup. 3) Setup window will apear just focus on it and installation setup will be started in few second. If it displaying the error message again again perform these above steps. Enjoy the installation.......... For more query mail me at:- abhizprogrammer@yahoo.com |
#5
|
|||
|
|||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
Not only is this a really old thread but the post above which has revived it has nothing to do with the topic at hand.
__________________
Alwyas use [code][/code] tags when posting code. |
#6
|
|||
|
|||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
uncompress it with zip or Rar compression utility on desktop and try
|
#7
|
|||
|
|||
Re: Invoke or beginInvoke cannot be called until the window handle has been created.
Try what? Why? The thread is 3 years old I doubt the OP is still waiting for an answer.
__________________
Alwyas use [code][/code] tags when posting code. |
![]() |
Bookmarks |
|
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|