Hi vlad781,
I created an executable example based on your requirements for you.
(I wouldn't recommend using a textbox for repetition input, have a look at NumericUpDown). Feel free to ask if anything is unclear...
using System;
using System.Windows.Forms;
namespace Repeat
{
static class Program
{
[STAThread]
static void Main()
{
Form form = new Form();
Button buttonStart = new Button();
buttonStart.Text = "Start";
buttonStart.Dock = DockStyle.Top;
Button buttonStop = new Button();
buttonStop.Text = "Stop";
buttonStop.Dock = DockStyle.Top;
TextBox textbox = new TextBox();
textbox.Dock = DockStyle.Top;
form.Controls.Add(buttonStop);
form.Controls.Add(buttonStart);
form.Controls.Add(textbox);
Timer timer = new Timer();
timer.Interval = 60000;
int iRepetitionCount = 0;
buttonStart.Click += delegate(object sender, EventArgs e)
{
timer.Stop();
if (String.IsNullOrWhiteSpace(textbox.Text))
{
TheFunction();
}
else
{
iRepetitionCount = 0;
if (!Int32.TryParse(textbox.Text, out iRepetitionCount))
{
MessageBox.Show("Invalid repetition count");
return;
}
TheFunction();
iRepetitionCount--;
timer.Start();
}
};
buttonStop.Click += delegate(object sender, EventArgs e)
{
timer.Stop();
};
timer.Tick += delegate(object sender, EventArgs e)
{
if (iRepetitionCount <= 0)
{
timer.Stop();
}
else
{
iRepetitionCount--;
TheFunction();
}
};
Application.Run(form);
}
static void TheFunction()
{
MessageBox.Show("I was called at " + DateTime.Now.ToString());
}
}
}