c# - I don't wan't to use Thread.Sleep with SHDocVw.ShellWindows -


i have program have shdocvw.internetexplorer instance running ie8 process. instance example code below runs. reason won't work without thread.sleep.

the browser.hwnd throws invalidcastexception instances in m_iefoundbrowsers if thread.sleep removed. when using thread.sleep works ie8 windows.

does know how in way not using thread.sleep? (i don't use sleep function, pushes problems future...)

example code:

internetexplorer m_iebrowser = null;   shellwindows m_iefoundbrowsers = new shellwindowsclass();   thread.sleep(10);                            foreach (internetexplorer browser in m_iefoundbrowsers)   {       try        {            if (browser.hwnd == (int)m_proc.mainwindowhandle)            {                 m_iebrowser = browser;                 break;            }         }         catch(invalidcastexception ice)         {               //do nothing. browser.hwnd not execute item.         }   }           

i came across following link seems hans's comment: http://weblogs.asp.net/joberg/archive/2005/05/03/405283.aspx

the article states:

the internet controls library contains “shellwindowsclass” collection of shell windows (e.g.: ie) spawned across desktop. component provides event handler called “windows registered” going hook to. once process has been launched, wait until corresponding window registered going connect our internet explorer control shell window found. determine if window found, iterate through registered windows , try find handle matches handle of process launched. use “manualresetevent” synchronization primitive wait amount of time window registered.

i expect you'd able map these ideas across problem relatively easily.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -