Question Cannot run Thread more than ounce

fabpan

New member
Joined
Jun 24, 2022
Messages
1
Programming Experience
5-10
Hi Everybody !

I need your help to solve the following issue please:

In my Window Form application I run a waiting form while I am executing some procedures.

This waiting form is run in a thread.

In running time, the first execution of my thread works fine but I cannot run it at the second try.

According to the documentation I have found on internet, It seems we cannot execute a thread more than ounce but I do not know how to implement my solution by using another method.

Here is my code (it is executed by clicking on a button):

C#:
private void WaitFormRun()
{
    // Execute my Waiting Form
    Application.Run( WF );
}


Thread LoadingThread = new Thread( WaitFormRun );
try
{
    LoadingThread.Start();
    MyProcedure1;
    switch( GetFileServerTag() )
    {
        case 1:
            MyProcedure2;
            break;
        case 2:
            MyProcedure3;
            break;
    }

}
catch (Exception E)
{
    MessageBox.Show(E.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    Logger.WriteLog("Error message: " + E.Message);
}
finally
{
    // Close my Waiting Form
    WF.Close();
}


It would be great if someone could guide me.

Thank you very much !
 
Last edited by a moderator:
Yikes! WinForms was never really designed to handled running multiple forms on different threads. Your basic design is flawed.

Anyway, taking WinForms out of the picture, that is correct you cannot restart a thread. You can create another thread though and have it use the same thread procedure (aka the delegate that you passed in).
 
Back
Top Bottom