C# Thread hört auf zu laufenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 C# Thread hört auf zu laufen

Post by Anonymous »

Ich habe einen Thread in C#, dies ist der Code, der ihn erstellt: < /p>

Code: Select all

mthrdMessageQueue = new Thread(() => sServiceMessageQueue());
mthrdMessageQueue.Start();
< /code>
mthrdMessageQueue
wird in der Klasse als:
deklariertThread mthrdMessageQueue;
< /code>
The thread body function:
///
/// Function sServiceMessageQueue thread body
///
public static void sServiceMessageQueue() {
FrmMain objThis = FrmMain.sobjThis;
try {
while (objThis != null
&& objThis.mthrdMessageQueue != null
&& objThis.mthrdMessageQueue.IsAlive == true) {
try {
//Clear busy flag to enable AT messages to be queued
sblnBusy = false;
Thread.Sleep(mcintServiceThreadSleep);
if (sobjThis == null) {
throw new Exception("\"sobjThis\" is null!");
}
sobjThis.ServiceMessageQueue();
} catch (Exception ex) {
FrmMain.sUpdateTaskbar(ex.Message);
} finally {
Console.WriteLine(strTimeStampMsg("sServiceMessageQueue..."));//HACK
}
} Console.WriteLine(strTimeStampMsg("sServiceMessageQueue...stopped!"));//HACK
} catch (Exception ex) {
FrmMain.sUpdateTaskbar(ex.Message);
} finally { Console.WriteLine(FrmMain.strTimeStampMsg("ServiceMessageQueue finished!"));
}
}
///
/// Static Function sUpdateTaskbar
///
///
Text to show
/// Optional, error count
/// Optional, function name
public static void sUpdateTaskbar(string strText, int intErrors = -1, string strFunction = "") {
if (msobjThis == null) {
return;
}
msobjThis.UpdateTaskbar(strText, intErrors, strFunction);
}
< /code>
The only message I see in the output up until the thread stops is:
24-02-2025 10:10:51.780>sServiceMessageQueue...
24-02-2025 10:10:51.880>sServiceMessageQueue...
24-02-2025 10:10:51.996>sServiceMessageQueue...
24-02-2025 10:10:52.097>sServiceMessageQueue...
24-02-2025 10:10:52.212>sServiceMessageQueue...
24-02-2025 10:10:52.314>sServiceMessageQueue...
< /code>
Then at some point in the application when I change some of the settings this thread stops running, there is nothing in the output to suggest that its stopped other than the above messages are no longer output. Can anyone help me to figure out what is going on?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post