[問題] 這樣是Timer的問題還是Label的問題?
我在CallbackFun裡面啟動Timer1 (Timer1每秒執行一次)
(在啟動前和啟動後使用Messagebox來查看Timer1的Enable狀態)
然後在Timer1裡面去變更label的Text
但是很奇怪的,如果啟動後所跳出的Messagebox沒有關掉,
Label就可以正常的更新Text,但是一但把Messagebox關掉,
就無法更新Text了,就算我在Timer1裡面設定中斷點也沒用
就好像是Timer1隨著Messagbox關閉也跟著停止了
但又好像是Label沒有更新,之後只要有隨便一個Messagebox跳出
Label就會更新顯示了...
這樣到底是什麼問題呢?又該如何解決= =?
程式大概是這樣的:
public partial class Form1 : Form
{
List<Label> playtimerlist = new List<Label>(); //存放label的List
delegate void SetUiTextCallback(object o,string text);
.
.
.
public bool Timer1Enabled
{
get { return timer1.Enabled; }
set { timer1.Enabled = value; }
}
public void setuitext(object o, string text)
{
Control c = (Control)o;
if (c.InvokeRequired)
{
SetUiTextCallback d = new SetUiTextCallback(setuitext);
c.Invoke(d, new object[] { o, text });
}
else
{
c.Text = text;
}
}
public void receiveCallBack(IAsyncResult ar) //給beginreceive使用
{
.
.
.
Messagebox.show(Timer1.Enabled.ToString());
Timer1Enabled = true;
Messagebox.show(Timer1.Enabled.ToString()); //這個Box關閉後
Timer1就停止?
}
.
.
.
int timers = 10;
private void timer1_Tick(object sender, EventArgs e)
{
timers--;
setuitext(playtimerlist[clientkey - 1], timers.ToString());
if (timers < 1)
{
setuitext(playtimerlist[clientkey - 1], "");
timers = 10;
timer1.Stop();
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.47.114
※ 編輯: sosokill 來自: 220.136.47.114 (01/03 23:41)
※ 編輯: sosokill 來自: 220.136.47.114 (01/03 23:43)
※ 編輯: sosokill 來自: 220.136.47.114 (01/03 23:52)
推
01/04 01:57, , 1F
01/04 01:57, 1F
→
01/04 01:57, , 2F
01/04 01:57, 2F
→
01/04 01:58, , 3F
01/04 01:58, 3F
→
01/04 01:58, , 4F
01/04 01:58, 4F
→
01/04 01:59, , 5F
01/04 01:59, 5F
→
01/04 03:34, , 6F
01/04 03:34, 6F
→
01/04 03:35, , 7F
01/04 03:35, 7F
→
01/04 03:35, , 8F
01/04 03:35, 8F
→
01/04 03:35, , 9F
01/04 03:35, 9F
推
01/04 19:19, , 10F
01/04 19:19, 10F