Create two ManualResetEvent
objects that you can wait on. Then create two timers:
ManualResetEvent Copy1Done = new ManualResetEvent(false);
ManualResetEvent Copy2Done = new ManualResetEvent(false);
Timer t1 = new Timer((s) =>
{
Class myClass0 = new Class();
myClass0.CopyFiles(15, cts0.Token);
Copy1Done.Set();
}, null, TimeSpan.FromMinutes(15), TimeSpan.FromMilliseconds(-1));
Timer t1 = new Timer((s) =>
{
Class myClass1 = new Class();
myClass0.CopyFiles(30, cts1.Token);
Copy2Done.Set();
}, null, TimeSpan.FromMinutes(30), TimeSpan.FromMilliseconds(-1));
Those are one-shot timers; they'll fire once, and then won't fire again.
Now, you want to wait up to two hours for the copies to complete. That's where the ManualResetEvent
objects come in. Create an array of the events:
WaitHandle[] handles = new WaitHandle[] {Copy1Done, Copy2Done};
// wait for both events to be signaled, or for two hours
if (!WaitHandle.WaitAll(handles, TimeSpan.FromHours(2)))
{
// took too long. Cancel the copies.
cts0.Cancel();
cts1.Cancel();
// you might want to wait here for the threads to exit.
// otherwise you might have a problem with a locked file.
}
// and run the program
RunExternalReportGeneratorEXE();