How can I make the progress bar update fast enough?

后端 未结 9 1586
礼貌的吻别
礼貌的吻别 2021-02-08 20:40

I\'m using a progress bar to show the user how far along the process is. It has 17 steps, and it can take anywhere from ~5 seconds to two or three minutes depending on the weath

9条回答
  •  迷失自我
    2021-02-08 21:02

    Try invoking the call to the waiting.setProgess() method since waiting seems to live in another thread and this would be a classic cross thread call (which the compiler warns you about if you let him).

    Since Control.Invoke is a bit clumsy to use I usually use an extension method that allows me to pass a lambda expression:

    waiting.ThreadSafeInvoke(() => waiting.setProgress(...));
    

    .

    // also see http://stackoverflow.com/questions/788828/invoke-from-different-thread
    public static class ControlExtension
    {
        public static void ThreadSafeInvoke(this Control control, MethodInvoker method)
        {
            if (control != null)
            {
                if (control.InvokeRequired)
                {
                    control.Invoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
        }
    }
    

提交回复
热议问题