Autor Beitrag
KanneM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: Mi 20.06.12 08:57 
Liebe Community,

Ich habe ein kleines Programm, das mit dem Quelltext einer Seite ein paar Operationen durchführt. Ich habe einen Webbrowser, von dem aus ich den Code lade.
Im Verlauf des Programms lädt das Prog mehrmals den Code. Dazwischen lass ich ihn aber immer wieder die Seite neu laden, damit der Quellcode aktualisiert wird.

Problem: Beim ersten Durchlauf geht es, beim Zweiten nicht mehr!

ausblenden C#-Quelltext
1:
2:
3:
4:
private void Methode(){
webBrowser1.Navigate("http://Seite.de");
strSource = webBrowser1.DocumentText.ToString();
}


Fehlermeldung beim zweiten Mal:

Zitat:
System.InvalidCastException wurde nicht von Benutzercode behandelt.
Message=Die angegebene Umwandlung ist ungültig.
Source=System.Windows.Forms
StackTrace:
bei System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()
bei System.Windows.Forms.WebBrowser.get_Document()
bei System.Windows.Forms.WebBrowser.get_DocumentStream()
bei System.Windows.Forms.WebBrowser.get_DocumentText()
bei DictCCTool.Form1.Suchen() in C:\Users\XXX\Projects\TestConsole\YYY\Form1.cs:Zeile 35.
bei DictCCTool.Form1.TimeCheck() in C:\Users\XXX\Projects\TestConsole\YYY\Form1.cs:Zeile 99.
bei DictCCTool.Form1._timer_Elapsed(Object sender, ElapsedEventArgs e) in C:\Users\XXX\Projects\TestConsole\YYY\Form1.cs:Zeile 89.
bei System.Timers.Timer.MyTimerCallback(Object state)
InnerException:


Zeile 35: strSource = webBrowser1.DocumentText.ToString();

Zeile 99: Ist der Methodenaufruf. Der wird durch das Timer-Event
Zitat:
void _timer_Elapsed(object sender, ElapsedEventArgs e)
ausgelöst!
Code:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            TimeCheck();
        }

        private void TimeCheck()
        {
            t.Stop();
            //
            
            //
            t.Interval = interval;
            Methodenaufruf(); //Hier wird die Methode() aufgerufen, siehe oben
            t.Enabled = true;
            t.Start();
        }


Timer: static System.Timers.Timer t = new System.Timers.Timer(); (am static liegt es nicht!)

Vielen Dank schonmal,

Kanne
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mi 20.06.12 12:13 
Hallo,

schau mal, ob die Fehlermeldung auch bei dem [url]System.Windows.Forms.Timer[/url] auftaucht (diesen solltest du immer in WinForms benutzen).
KanneM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: Mi 20.06.12 14:36 
Bei System.Windows.Forms.Timer habe ich aber kein Ellapsed-Event, da bekomme ich mit meinem Programm Probleme...
Es muss doch aber an was anderen liegen, oder?
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 20.06.12 15:04 
user profile iconKanneM hat folgendes geschrieben Zum zitierten Posting springen:
Bei System.Windows.Forms.Timer habe ich aber kein Ellapsed-Event
...aber ein äquivalentes, schau bitte noch einmal nach ;) .

_________________
>λ=
KanneM Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26
Erhaltene Danke: 1

Win98, Win XP, Win 7
Java, C#
BeitragVerfasst: Mi 20.06.12 22:23 
Also, hier msdn.microsoft.com/d...er%28v=vs.80%29.aspx finde ich kein Ellpsed-äquivalentes-Event... sorry =/

was ich mir vorstellen könnte ist, dass ich beim tick-event abfrage, wieviel noch übrig ist vom timer?!

LG