Thema: InvalidOperationException
-
02.07.2012, 21:19 #1
- Registriert seit
- 18.11.2011
- Beiträge
- 457
- Blog Entries
- 1
Thanked 296 Times in 94 PostsInvalidOperationException
Immer, wenn ich mit meinem Bot eingeloggt bin und dann über das X oben rechts schließe, bekomme ich eine InvalidOperationException. Die Form verschwindet, jedoch wird der Nick nicht ausgeloggt und das Debugging nicht beendet.
InvalidOperationException wurde nicht behandelt.
Invoke oder BeginInvoke kann für ein Steuerelement erst aufgerufen werden, wenn das Fensterhandle erstellt wurde.
this.rtb_Chatverlauf.Invoke((MethodInvoker)delegate()
{
rtb_Chatverlauf.AppendFText(str + "\n"); // Nachricht im Verlauf anzeigen...
rtb_Chatverlauf.ScrollToCaret(); // ... und zum Ende scrollen
});
PS: Wäre sicherlich noch gut, wenn ich erwähnt hätte, dass ich dafür ein eigenes Controll als Chatbox verwende.
Hier der AppendFText-Teil davon:
public void AppendFText(string text)
{
bool isBold = false;
bool isItalic = false;
bool isEscaped = false;
FontStyle currStyle = FontStyle.Regular;
string tempText = String.Empty;
Color currColor = Color.Empty;
for (int i = 0; i < text.Length; i++) {
char tempChar = text[i];
if (tempChar == '\\') {
isEscaped = !isEscaped;
if (text.Length > i && isEscaped && text[i + 1] == '\\')
tempText += '\\';
continue;
}
if (tempChar == '_' && !isEscaped) {
if (tempText != String.Empty) {
AppendText(tempText, currColor, currStyle);
tempText = String.Empty;
}
if (isBold)
currStyle -= FontStyle.Bold;
else
currStyle |= FontStyle.Bold;
SetStyle(currStyle);
isBold = !isBold;
continue;
}
else if (tempChar == '"' && !isEscaped) {
if (tempText != String.Empty) {
AppendText(tempText, currColor, currStyle);
tempText = String.Empty;
}
if (isItalic)
currStyle -= FontStyle.Italic;
else
currStyle |= FontStyle.Italic;
SetStyle(currStyle);
isItalic = !isItalic;
continue;
}
else if (tempChar == '#' && !isEscaped) {
tempText += "\r\n.... ";
continue;
}
else if (tempChar == '°' && text[i + 2] == '°') {
if (tempText != String.Empty) {
AppendText(tempText, currColor, currStyle);
tempText = String.Empty;
}
currColor = GetColor(text[i + 1]);
i += 2;
continue;
}
if ((tempChar == '_' || tempChar == '"' || tempChar == '#') && isEscaped)
isEscaped = false;
tempText += tempChar;
}
if (tempText != String.Empty)
AppendText(tempText, currColor, currStyle);
}Geändert von Pwned (02.07.2012 um 21:25 Uhr)
-
02.07.2012, 21:49 #2
- Registriert seit
- 15.11.2011
- Beiträge
- 7.852
- Blog Entries
- 5
Thanked 9.363 Times in 3.202 PostsAW: InvalidOperationException
Hat nix mit dem custom control zutun, ist ein simpler Multithreading-Fehler.
Das Control wird im Main-Thread erzeugt und nach dem Schließen dort natürlich auch wieder zerstört.
Dein 2. Thread läuft trotzdem weiter und versucht auf die bereits zerstörte Instanz zuzugreifen => failed natürlich.
Einfach vorher prüfen ob die Instanz überhaupt noch existiert, z.B. so
if (!controlBla.IsDisposed) {
// invoken & Zugriff auf das Control
}
Ähnliche Themen
-
Win7 CLR20r3 System.InvalidOperationException Problem
Von Bazs im Forum WindowsAntworten: 2Letzter Beitrag: 25.01.2014, 13:19
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.