Your code is a bit confusing but basically you are looking for the following
static void Main(string[] args) {
var myObject = new Class1();
myObject.Do();
// give the program 10 minutes to run. This is arbitrary so you will want to change
// to something realistic or have a callback to signal "done".
System.Threading.Thread.Sleep(10 * 60 * 1000);
}
That should do it or at least get you started!
Other Note - One other note is the second timer calls a method named net_Tick
. I don't see this in the code presented so I assume there are no issues with that...
Alternative Approach
One other approach instead of making the main thread pause is to block the Do
method until the timer is done (or you want to stop). To do this I have added just the pieces of code that need to change in Class1
below:
public class Class1 {
// add a variable for timer complete
private bool timerComplete = false;
private int timerIndex = 0;
public void Do()
{
t.Enabled = true;
// start timer same as normal:
t.Interval = 10 * 1000;
t.Tick += new EventHandler(t_Tick);
t.Start();
// busy wait to block the thread
while (!timerComplete) {
System.Threading.Thread.Sleep(1000);
}
}
void t_Tick(object sender, EventArgs e)
{
// give this a stopping point
timerIndex++;
if (timerIndex >= 10) {
timerComplete = true;
return;
}
// leave the rest of the tick as it was before...
}
}
Once you do this you can remove the call to Sleep
from the Main
routine and everything should still work. Best of luck!