I know how to start a function in x seconds, its something like this:
private Timer timer1;
public void InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 2000; // in miliseconds
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
function1();
function2();
function3();
}
The problem here: The functions cannot run at the same time. Function2
can only run if Function1
is done. But I want them running at the same time. Thats why I could do this:
private void timer1_Tick(object sender, EventArgs e)
{
Parallel.Invoke(
() => Function1(),
() => Function2(),
() => Function3()
);
}
Is this the smartest way to do it in c#? What I dont understand with Parallel.Invoke
: what if my timer is set for 5 sec and after 5 sec function1,2 and 3 are not done but I call them all again. Do I start these functions in a new thread? Are there after some calls x-threads running function1() (at the same time)? Wondering is that really healthy.
If somebody would like to get more information: function1
is just there to copy file x from folder a to b, function2
is only there to read all files from folder b and save the information and function3
is only there to check the connection and if there is a connection send the appropriate file to somebody.
Any suggestions to the code? Thank you