您的位置:程序门 -> .net技术 -> vb.net



關於多線程進度條的問題


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


關於多線程進度條的問題
发表于:2007-03-09 15:24:02 楼主
以下是我的源代碼

imports   system.threading

public   class   form1
        private   delegate   sub   invokedelegate()
        dim   th1   as   thread
        dim   th2   as   thread

        private   sub   delegate1()
                begininvoke(new   invokedelegate(addressof   thread1))
        end   sub

        private   sub   delegate2()
                dim   myinvoker   as   methodinvoker
                myinvoker   =   new   methodinvoker(addressof   thread2)
                begininvoke(myinvoker)
        end   sub

        private   sub   button1_click(byval   sender   as   system.object,   byval   e   as   system.eventargs)   handles   button1.click
                th1   =   new   thread(addressof   delegate1)
                th2   =   new   thread(addressof   delegate2)
                th1.start()
                th2.start()
        end   sub

        private   sub   thread1()
                dim   i   as   integer
                do   while   true
                        progressbar1.value   =   i
                        i   +=   1
                        if   i   =   100   then   i   =   0
                        thread.sleep(200)
                loop
        end   sub

        private   sub   thread2()
                dim   ii   as   integer
                do   while   true
                        progressbar2.value   =   ii
                        ii   +=   1
                        if   ii   =   100   then   ii   =   0
                        thread.sleep(250)
                loop
        end   sub

end   class


執行不會出錯
可是只有一個進度條會走動
這是怎麼回事呀?
要如何改進呢??
发表于:2007-03-09 15:41:221楼 得分:0
你的代码有问题,这样做始终在一个   do   while   true出不来
   
*****************************************************************************
欢迎使用csdn论坛专用阅读器   :   csdn   reader(附全部源代码)  

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
发表于:2007-03-09 16:19:582楼 得分:0
那我要如何寫才能讓兩個進度條同時走動呀???
发表于:2007-03-09 16:48:413楼 得分:0
private   delegate   sub   invokedelegate(byval   i   as   integer)
        dim   th1   as   thread
        dim   th2   as   thread

        private   sub   delegate1()
                dim   i   as   integer
                do   while   true
                        begininvoke(new   invokedelegate(addressof   thread1),   i)

                        i   +=   1
                        if   i   =   100   then   i   =   0
                        thread.sleep(200)
                loop

        end   sub

        private   sub   delegate2()
                dim   ii   as   integer
                do   while   true
                        begininvoke(new   invokedelegate(addressof   thread2),   ii)
                        ii   +=   1
                        if   ii   =   100   then   ii   =   0
                        thread.sleep(250)
                loop
               
        end   sub

private   sub   thread1(byval   i   as   integer)
                progressbar1.value   =   i
        end   sub

        private   sub   thread2(byval   i   as   integer)
                progressbar2.value   =   i
        end   sub


快速检索

最新资讯
热门点击