System.Timers.Timer,不更新FORM进度条控件,请高手指导
--------------------编程问答-------------------- 不要引用System.Timers使用System.Forms.Timers,对应事件为Tick --------------------编程问答-------------------- Dim TimerMove As System.Forms.Timer
AddHandler TimerMove.Tick, AddressOf TimerMove_Tick --------------------编程问答-------------------- System.Timers.Timer需要Invoke去更新进度条,晓得了哇。。 --------------------编程问答--------------------
System.Forms.Timer,不用这个,因为,他会卡程序界面。
Invoke去更新,如下,结果就是报错
在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。
Form1.TextBox1.Invoke(pInvoke, New Object() {iStr})
报错这一句。
--------------------编程问答-------------------- 你这个地方为什么不用Invoke
Public Sub TimerMove_Tick(ByVal sender As Object, ByVal e As EventArgs)
If itimer = 5 Then
itimer = 0
MsgBox(itimer)
ShowTextbox(itimer.ToString)
Else
itimer = itimer + 1
Form1.ProgressBar1.Value = itimer
MsgBox(itimer)
End If
End Sub
Delegate Sub dl_ShowTextbox(ByVal iStr As String)
Public Sub ShowTextbox(ByVal iStr As String)
Dim pInvoke As New dl_ShowTextbox(AddressOf ShowTextbox)
Form1.TextBox1.Invoke(pInvoke, New Object() {iStr})
MsgBox("Form1.TextBox1.InvokeRequired = True")
Form1.TextBox1.Text = iStr
End Sub
Form1.ProgressBar1.Value = itimer--------------------编程问答--------------------
MsgBox(itimer)
在这里,改为
Dim pInvoke As New dl_ShowTextbox(AddressOf ShowTextbox)
Form1.TextBox1.Invoke(pInvoke, New Object() {itimer.ToString})
报错:在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。
刚才在网上查了一下。
http://tieba.baidu.com/p/658883698
Invoke其实是me.Invoke,在类中不能使用的..即使是FormName.Invoke也不行..
这人这样回复,我感觉不对吧。不可能,timer或者多线程中,不能更新ui界面吧。
--------------------编程问答-------------------- 需启动事件:
AddHandler , AddressOf TimerMove_Tick
补充:.NET技术 , VB.NET