multithreading - C# Update ProgressBar from Thread -
i have windows form in xaml contains progress bars. threads spawned, jobs run, , status of jobs shown progress bars.
it's working ok, want limit number of jobs can run @ 1 time.
protected int executingthreads = 0; int maxthreadcount = 3; object lockobj = new object(); public virtual void start() { inqueue = new queue<xelement>(); loadqueue(); while (inqueue.count != 0) { xelement request = inputqueue.dequeue(); system.threading.threadpool.queueuserworkitem(new system.threading.waitcallback(dowork), request); /* lock (lockobj) { executingthreads++; while (executingthreads == maxthreadcount) thread.sleep(1); } */ } /* while (executingthreads != 0) thread.sleep(1); */ }
to limit number of jobs running @ 1 time, added code that's shown here commented out lock , sleep. seems limit number of jobs running @ 1 time , jobs complete successfully.
but progressbar no longer incrementally displaying updates -- until jobs finish , shown completed. assume sleep prevents progressbar ui refresh. how can fix that? solution application.doevents() ?
Comments
Post a Comment