Application continues to run even after it is closed

1

I'm having a problem with my application. It remains in the list of processes even after its completion, in addition to it, the ClickOnce application also appears in the list.

Scenery

My application communicates with a ratchet through a dll , and this communication is managed by a thread in the while(true) state.

It turns out that eventually thread is terminated without explanation / exception. I then have another thread that verifies that the thread original .isAlive , if it is false the same as a new call in thread . But at this point an error occurs, stating that it can not access dll because it is being used by another thread .

Here is an example of the code:

public static Thread th;
public static Thread thVerify;

void btnIniciar_Click(...)
{
    th = new Thread(() => IniciarCatraca());
    thVerify = new Thread(() => IniciarVerificacaoThread(th));
    th.Start();
    thVerify.Start();
}

public void IniciarVerificacaoThread(Thread t)
{
    try
    {
        while(true)
            if (t == null || !t.isAlive())
                th = new Thread(() => IniciarCatraca());
    }
    catch(Exception ex)
    {
        CallCatch(ex);
    }
 }

It correctly checks to see if the thread th is active, but still gives exception when attempting to start the ratchet again, stating that dll is already in use by another thread , with thread ending!

Then I end the application and open the process manager. There are two processes ClickOnce and ProjetoCatraca . If I open the application again and try to communicate with the ratchet without finishing the processes, I get the same error, the dll is being used by another thread .

Could you tell me why the application remains in the process list even after it's closed?

Can this be caused by the use of thread ?

Is there a way to check for thread using methods other than those expressed in my code? Any suggestions?

    
asked by anonymous 24.08.2017 / 16:01

1 answer

0

You have to end the thread when you close the program, otherwise it will always run, alias, to do better, just create a static bool called > stopThread , and within the while of the thread, check if stopThread is active if it is simply a break p>     

30.06.2018 / 20:58