There is a functional that works asynchronously in a separate thread. After 3 minutes have elapsed, it is necessary to interrupt the execution. Something like pseudocode like:
Timer1.start() //Запустить таймер funct_work(); // Запускаем функционал while (Timer1.value() < 3); // проверяем прошло ли 3 минуты, если нет продолжаем работу. Timer1.Stop(); // время работы вышло While at the moment it turned out this:
funct_work(); System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(timer_Tick); // в функции timer_tick идет увеличение глобальной переменной timer.Start(); if (glob_time < 180){;}else{timer.Stop()} However, the problem is that the condition is satisfied 1 time. If you put a loop, the timer_tick () function is not executed.
Helped to make an announcement System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer (); globally. Move out timer.Tick + = new EventHandler (timer_Tick); in main (for each time the function was started, another handler was hung and the timer was accelerated) Check glob_time was sent to the timer_Tick function. After that, everything worked.
if (glob_time < 180){conditionif (glob_time < 180){- it will not work again. Use the task scheduler. - And