ผมอ่านค่าจาก php ด้วย C# และใช้ timer1 จับเวลาโดยกำหนดค่า Interval เป็น 30,000 ครับ แต่ทำไมมันแสดง MessageBox 2 ครั้งครับไม่เข้าใจเลย พอถึงเวลามันแสดงครั้งนึง พอรอสักพักก็แสดง MeassageBox ขึ้นมาอีกครั้งนึง แก้ยังไงครับ
[open_code]
private void timer1_Tick(object sender, EventArgs e)
{
bool flag = false;
//timer1.Start();
WebClient client = new WebClient();
Stream stream = client.OpenRead("
http://localhost/time.php");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
//textBox1.Text = content;
if (content == "14:02")
{
if (!flag)
{
MessageBox.Show(new Form() { TopMost = true }, "หมดเวลาแล้ว");
flag = true;
}
}[/close_code]
C# Timer แสดง MessageBox 2 ครั้ง อยากให้แสดงแค่ครั้งเดียวแก้ยังไงครับ
[open_code]
private void timer1_Tick(object sender, EventArgs e)
{
bool flag = false;
//timer1.Start();
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://localhost/time.php");
StreamReader reader = new StreamReader(stream);
String content = reader.ReadToEnd();
//textBox1.Text = content;
if (content == "14:02")
{
if (!flag)
{
MessageBox.Show(new Form() { TopMost = true }, "หมดเวลาแล้ว");
flag = true;
}
}[/close_code]