当前位置:编程学习 > C#/ASP.NET >>

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去更新进度条,晓得了哇。。 --------------------编程问答--------------------
引用 3 楼 mngzilin 的回复:
System.Timers.Timer需要Invoke去更新进度条,晓得了哇。。




System.Forms.Timer,不用这个,因为,他会卡程序界面。


Invoke去更新,如下,结果就是报错

在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。

  Form1.TextBox1.Invoke(pInvoke, New Object() {iStr})

报错这一句。

 


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

--------------------编程问答-------------------- 你这个地方为什么不用Invoke

 
            Form1.ProgressBar1.Value = itimer
            MsgBox(itimer)
--------------------编程问答--------------------
引用 5 楼 mngzilin 的回复:
你这个地方为什么不用Invoke

 
C# code12            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
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,