我正在使用System.Threading.Timer
计时器对象。我需要在tick方法中暂停计时器,以便我可以做一些事情,然后重新启动计时器再次开始计时。
private async void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
timer1.Enabled = false;
if (btn7)
{
timer.Stop();
}
fetch_hashtag();
br2(); //posting in hashtages
Console.WriteLine("waiting");
while (timer1.Enabled == false)
{
Application.DoEvents();
if (webBrowser2.Url.AbsoluteUri.Contains("blank"))
timer1.Enabled = true;
}
await Task.Delay((int)TimeSpan.FromMinutes(double.Parse(textBox4.Text)).TotalMilliseconds);
timer1.Start();
}
private async void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
timer1.Stop();
timer1.Tick -= timer1_Tick;
// do some stuff
timer1.Enabled = true;
timer1.Start();
timer1.Tick += timer1_Tick;
}