i use webbrowser control in c# check couple search engine results sometime no reason gets stuck. first thought make each searching function thread , use thread.abort() timer couldn't handle ui controls (including webbrowser) no matter i've tried. has solution me? example great cause tried many things , keep getting these exceptions.
i believe can use webrequest in background worker & avoid difficulties of dealing com threading model. can use webrequest.timeout handle think taking long.
try this:
static void main(string[] args) { backgroundworker bg = new backgroundworker(); bg.dowork += backgroundworker_dowork; bg.runworkerasync(new list<object> { "http://download.thinkbroadband.com/512mb.zip" }); while (true) {} } private static void backgroundworker_dowork(object sender, doworkeventargs e) { console.writeline("starting operation."); backgroundworker bw = sender backgroundworker; list<object> args = (list<object>)e.argument; var url = (string)args[0]; webrequest request = webrequest.create(url); request.timeout = 300; try { webresponse response = request.getresponse(); console.writeline("request successful."); } catch (exception ex) { console.writeline("request timed out."); } }
webbrowser component should use when want embed instance of ie presentation layer. unless need this, can use more lightwweight.
Comments
Post a Comment