i want realize a simple application that in a specific and precise time, with webbrowser control, go to the webpage.
public partial class Form1 : Form
{
System.DateTime timeStart = new System.DateTime(2016, 05, 25, 19, 30, 00, 00);
TimeSpan sub;
bool timeExpires = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 100;
timer1.Start();
while(timeExpires)
{
webBrowser1.Navigate("https://www.google.it/");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
System.DateTime Now = System.DateTime.Now;
sub = timeStart.Subtract(Now);
if ((int)sub.TotalSeconds == 0)
{
this.timer1.Stop();
MessageBox.Show("ok, Time is up!");
timeExpires = true;
}
else
{
textBox1.Text = sub.ToString();
}
}
}
after the timecount, when timer1.stop() is set, the messagebox is show.
But webbrowser don't run .
I know that i use a bool variable timeExpires is an "antiquated" method.
I have two question :
- where is the best pratice or best way to "notify" at webbrowser or any other thing that countdown is finish and now is time to run.
- where is problem with this approch(boolean variable)? how I can run with this approch even if isn't the best way?
Thanks so much