Is it possible for a subprocess to end the parent process?

9

The problem is as follows.

I have a thread that connects to a Telnet, the problem is that sometimes the telnet is stuck, or the connection is lost momentarily and the program that connects with the telnet is pointing to nothing.

The problem this I treat so that, there is a parent thread, which is responsible for restarting the son thread every 30 minutes.

while (true)
        {
            /*
             * Bucle que reinstancia el hilo, reiniciándolo para que cada X tiempo 
             * se relance el servicio sin importar como esté. 
             */

            error=false;

            try
            {
                ThreadStart consola = new ThreadStart(telnetListener);
                Thread thread = new Thread(consola);
                thread.Start();

                Thread.Sleep(1000 * 60 * 30);
                thread.Abort();
            }
            catch (Exception e)
            {
                log("FALLO" + e.Message);
                error = true;
            }

The hierarchy is as follows.

Hilo padre
   |
   |Hilo hijo
      |
      | Escuchamos los mensajes que llegan de Telnet

Then what fails me is that in the program I get an exception in the son thread, I keep the exception in a log and it says "sub-process aborted"

And I do not know how to solve it.

    
asked by Aritzbn 06.02.2018 в 17:46
source

1 answer

-1

Maybe it would work to declare the thread out of the while, so you control the start and the abort of the same instance as you already do:

   ThreadStart consola = new ThreadStart(telnetListener);
   thread = new Thread(consola);

    while (true)
    {
        /*
         * Bucle que reinstancia el hilo, reiniciándolo para que cada X tiempo 
         * se relance el servicio sin importar como esté. 
         */

        error=false;

        try
        {
                          thread.Start();

            Thread.Sleep(1000 * 60 * 30);
            thread.Abort();
        }
        catch (Exception e)
        {
            log("FALLO" + e.Message);
            error = true;
        }
    
answered by 17.12.2018 в 07:46