Posible (s) forma (s) de iniciar un hilo sin bloqueo que permanece activo

What would be possible way(s) to start non-blocking thread which then runs a few System.Timers.Timer based tasks? Working on writing this code a non-UI library. I have seen similar questions and the advice on them have been to convert the library into Windows Service - not sure if that is an option for me.

P.ej, Process.Start() would implement non-blocking thread which instantiates and executes Timers based functions.

public void Start()
   Timer t1 = new Timer(10000);
   Timer t2 = new Timer(15000);
   t1.Elapsed += new ElapsedEventHandler(T1Task);
   t2.Elapsed += new ElapsedEventHandler(T2Task);
   t1.Enabled = true;
   t2.Enabled = true;

   // the following is blocking, of course 
   while (true)

In code above, if the library call is invoked via WinForm, the GUI would obviously block.

preguntado el 01 de febrero de 12 a las 04:02

Please don't prefix your titles with ".NET 4.0 [c#]: " and such. That's what the tags are for. -

1 Respuestas

Just use System.Threading.Timer. It's non blocking and fires events on a non-UI thread.

Respondido 01 Feb 12, 08:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.