multithreading - C# Catching Exception From Invoked Delegate on another Thread -


i have code follows. running on "thread 2"

webbrowser browser = this.webbrowser     browser.invoke(new methodinvoker(delegate { browser.document.getelementbyid("somebutton").invokemember("click"); })); thread.sleep(500); browser.invoke(new methodinvoker(delegate { browser.document.getelementbyid("username").setattribute("value", username); })); //folowed several more similar statments 

essentially invoking methods on webbrowser control created on different thread, "thread 1".

if element on current page loaded in browser not contain element "somebtn" or "username", exception thrown "thread 1".

is there way catch exception on "thread 2"? know use try catches within delegates , have special delegate returns value(like exception), there way around options?

note*: require thread.sleep particular page requires delay between events. if there way combine these events single delegate(while retaining form of non-blocking delay), think work , wrap of them in single try catch , create delegate returns exception.

although control.invoke() executes delegate on ui thread - still synchronous call. synchronous meaning invoke not return until delegate has completed execution (or exception thrown). can catch exceptions thrown there.

webbrowser browser = this.webbrowser; try {         browser.invoke(new methodinvoker(delegate { browser.document.getelementbyid("somebutton").invokemember("click"); }));     thread.sleep(500);     browser.invoke(new methodinvoker(delegate { browser.document.getelementbyid("username").setattribute("value", username); })); } catch(exception e)  {     //catch in thread 2 } 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -