none
C# 多线程问题 RRS feed

  • 问题

  • 代码如下:

    按钮点击事件里面:

    Thread thread1=new Thread (new ThreadStart(fangfa1()));

    Thread thread2=new Thread (new ThreadStart(fangfa2()));

    thread1.Start();

    thread2.Start();

    下面是方法:

    private void fangfa1()

    {

    show1();

    }

    private void fangfa2()

    {

    show2();

    }

    下面是委托:

    private delegate void del1();

    private void show()

    {

    if (InvokeRequired)
                {
                    BeginInvoke(new del1(show), new object[] { });
                    return;
                }

                for (int i = 1; i <=100; i++)
                {
                    this.progressBar1.Value = i;
                    shows();
                }

    }

    private delegate void del2();

    private void show2()

    {

    if (InvokeRequired)
                {
                    BeginInvoke(new del2(show2), new object[] { });
                    return;
                }

                for (int i = 1; i <=100; i++)
                {
                    this.progressBar2.Value = i;
                    shows();
                }

    }

     

    问题:

    我要这两个进度条一起走动,请问,代码该怎么改?

    2011年5月16日 3:32

答案