I must say that with
webbrowser.Navigate("tra.ta"); There are no problems. The problems start from this moment:
webbrowser.Document.GetElementById("switch_to_login_button").InvokeMember("click"); and so on. Tell me how to use this component in the background, and it is very desirable that the work was visible in the GUI and it was alive. From what I tried: 1. Work in backgroundworker, with a parameter
CheckForIllegalCrossThreadCalls = false. 2. Work there, using
this.BeginInvoke(new Action(() => It did not fit, because there was no point, all the same, the form is hanging. 3. Create a new instance of WebBrowser in backgroundworker. And also in the stream created like this:
System.Threading.Thread t = new System.Threading.Thread(() => { WebBrowser wb = new WebBrowser(); wb.Navigate("https://freebitco.in/"); Thread.Sleep(5000); wb.Document.GetElementById("login_form_btc_address").SetAttribute("value", login.Text); }); t.ApartmentState = System.Threading.ApartmentState.STA; t.Start(); 4. The attempt to install Awesomium, which failed, because VS did not want to accept the assembly, for some unknown reason.
If I still remember what I tried, I will write, because I tried a bunch of methods, but I did not find a solution. I fight all day.
UPD: Here is the code that I use in the thread (both Thread and BackgroundWorker:
System.Threading.Thread t = new System.Threading.Thread(() => { this.BeginInvoke(new Action(() => { mainweb.Document.GetElementById("menu_drop").InvokeMember("click"); mainweb.Document.GetElementById("drop1").Children[1].Children[0].InvokeMember("click"); Thread.Sleep(2000); int losts = 0; int wins = 0; do { mainweb.Document.GetElementById("double_your_btc_stake").SetAttribute("value", num.Text); if (play(Convert.ToBoolean(button))) { wins++; if (button == 0) { button = 1; } else { button = 0; } } else { losts++; num.Text = Convert.ToString(decimal.Parse(Convert.ToString((decimal.Parse(num.Text) * 2)), NumberStyles.Float)); mainweb.Document.GetElementById("double_your_btc_stake").SetAttribute("value", num.Text); } l_losts.Text = "Проигрышей: " + losts; l_wins.Text = "Выигрышей: " + wins; } while (losts < Convert.ToInt32(max_losts.Text) && wins < Convert.ToInt32(max_wins.Text)); })); }); t.ApartmentState = System.Threading.ApartmentState.STA; t.Start();
CheckForIllegalCrossThreadCalls = false- this somehow sounds very wrong. And what does “form still hang” mean? Here, please, more. - VladD 4:04 pmThread.Sleep(2000);- not surprising. - VladD