C# problem with webBrowser.ReadyState

webBrowser , problems , csharp Ljubljana, Slovenia
  • 8 years ago

    Hi,

    here I'm stucked again :crying:

    I got this error:

    System.InvalidCastException was unhandled by user code

    [CODE]System.InvalidCastException was unhandled by user code Message=Specified cast is not valid. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation() at System.Windows.Forms.WebBrowser.getDocument() at System.Windows.Forms.WebBrowser.getReadyState() at test.Form2.timer1Tick(Object sender, EventArgs e) in C:\Users\Tilen\documents\visual studio 2010\Projects\test\Form2.cs:line 410 at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.DoEvents() at test.Form2.backgroundWorker1DoWork(Object sender, DoWorkEventArgs e) in C:\Users\Tilen\documents\visual studio 2010\Projects\test\Form2.cs:line 350 at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument) InnerException: [/CODE]

    This error I get with that:

    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();

    I dont know why I get that error, on the other applications this has worked.

    Here is the complete function:

    [CODE]private void timer1Tick(object sender, EventArgs e) { MessageBox.Show("timer time"); timer1.Stop(); timer1.Interval = 300000; for (int i = 0; i <= 199; i++) { string idmesta, thtml, trenutno, trenutno2; int[] surovine = new int[4]; int[] tippolja = new int[19]; int[] indeksminsurovin = new int[4]; int[,] levelpolj = new int[19,3]; int templevel, zitonauro; bool prvaizbira = true;

                id_mesta = globalno.mesta[i, 0];
                if (id_mesta == "") break;
                if (File.Exists("UserConfig\\" + id_mesta + ".txt"))
                {
                    webBrowser1.Navigate(globalno.g_userServer + "dorf1.php?newdid=" + id_mesta);
                    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();
             //       while (webBrowser1.IsBusy == false) Application.DoEvents();
             //       while (webBrowser1.IsBusy == true) Application.DoEvents();
                    thtml = webBrowser1.DocumentText;
                    string tipmesta = funkcije.StringRegExp(thtml, "id=\"village_map\" class=\"", "\"");
                    switch(tipmesta)
                    {
                        // 0-žito, 1-les, 2-glina, 3-železo
                        case "f1": tip_polja[1] = 0; tip_polja[2] = 0; tip_polja[3] = 1; tip_polja[4] = 0; tip_polja[5] = 0; tip_polja[6] = 2; tip_polja[7] = 3; tip_polja[8] = 0; tip_polja[9] = 0; tip_polja[10] = 3; tip_polja[11] = 3; tip_polja[12] = 0; tip_polja[13] = 0; tip_polja[14] = 1; tip_polja[15] = 0; tip_polja[16] = 2; tip_polja[17] = 1; tip_polja[18] = 2; break;
                        case "f2": tip_polja[1] = 3; tip_polja
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”