|
-
April 4th, 2012, 02:25 AM
#5
Re: Delegate, Invoke, Threads and anormal bug
*victory fanfare from final fantasy*
**** you won ! Just nammed my threads better and check with the Debug->Windows->Threads (didn't knew that feature and it allowed me to understand immediatly) and found that I'm in a deadlock
Serveur.Close() is called by GUI, but hangs in myThreadListener.Join();
And the listener thread is blocked on this.Invoke(new DeleguePourUpdateLog(this.UpdateLog), new object[] { e.message });
meaning it waits for the GUI to process data but the GUI is already waiting.
This is pure school deadlock case :/
I cheated by creating a closing thread that'll manage all closing without freezing the GUI
Code:
public static void Close(bool _bClose)
{
bClose = _bClose;
myThreadClosing = new Thread(new ThreadStart(CloseProcessing));
myThreadClosing.Start();
}
private static void CloseProcessing()
{
Thread.CurrentThread.Name = "CloseProcessing";
UpdateLog("[INFO] Shutdown in progress" + Environment.NewLine);
// C'est le manager qui va fermer tout le monde
bListenerEnable = false;
bManagerEnable = false;
if (myThreadListener != null)
{
if (myThreadListener.IsAlive)
{
UpdateLog("[INFO] Attente fermeture listener" + Environment.NewLine);
myThreadListener.Join();
}
}
// Normalement le manager est déj* fermé !
if (myThreadManager != null)
{
if (myThreadManager.IsAlive)
{
UpdateLog("[INFO] Attente fermeture manager" + Environment.NewLine);
myThreadManager.Join();
}
}
UpdateLog("[INFO] Fermeture terminée" + Environment.NewLine);
if (bClose)
{
Environment.Exit(0);
}
}
I know it's not perfect but this way I keep control of the GUI
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|