Understood: for example, imagine a button in my form. When the user clicks on the button, some void method should start after 30 seconds.
There would be an empty DoAfterDelay method that takes two input parameters. The first method is the method (using delegates), and the second is the time interval. So, I will have:
public delegate void IVoidDelegate(); static void DoAfterDelay(IVoidDelegate TheMethod, TimeSpan Interval) {
So, I just need a piece of code to pause the process for a certain amount of time. Before that, I used this code for this:
System.Threading.Thread.Sleep(Interval);
But this code does not suit me, because it stops the whole process and stops the program. I do not want the program stuck in the DoAfterDelay method. This is why Thread.Sleep useless.
So can anyone suggest a better way? Of course, I searched about this, but most of the solutions I found were based on using a timer (like here, for example). But using a timer is my last opinion, because the method should be run once, and using timers makes the program incomprehensible to read. Therefore, I am looking for the best solution, if any. Or maybe I should use timers?
I think I should play with themes, but not sure. So I wonder if anyone can lead me to a solution. Thanks in advance.
multithreading c # timer winforms
Mostafa farzán
source share