c# - Why do I get this error when using a thread? -
so, got program working, becomes unresponsive when run it, decided run in thread. now, kept same, instead of using button run code directly, i'm using button run thread contains code. program doing creating request webpage, getting cookie webpage, run through list of numbers, using numbers create different post requests using cookie log in.
working:
private void button3_click(object sender, eventargs e) { string cookie = webbrowser1.document.cookie; list<string> removals = new list<string>(); foreach (string s in listbox1.items) { //do stuff } }
not working:
thread th; public void thread() { string cookie = webbrowser1.document.cookie; list<string> removals = new list<string>(); foreach (string s in listbox1.items) { //do stuff } } private void button2_click(object sender, eventargs e) { th = new thread(thread); th.start(); }
error: http://prntscr.com/1mabtb
thank you.
you're presumably using winforms in case should invoke actions on webbrowser1 control such interactions performed on ui thread instead of newly created thread. see series of answers here:
Comments
Post a Comment