Progress Bar in WPF application for long running WCF service

2 posts, 0 answers
  1. Aria
    Aria avatar
    1 posts
    Member since:
    May 2017

    Posted 04 May 2017 Link to this post

     I have a long running WCF service and a client that consumes it via WPF. Am using a Progress Bar to notify the client of the percentage completion for a particular process (a method in WCF: I need to be able to display the percentage based on the looping counter in the service)
    I have used Background Worker to display progress percentage but it does not display the progress correctly. (displays just 0 and 100 not the in between values) Everything works fine in DEBUG mode but not in RELEASE mode! (Progress bar is updated sequentially in DEBUG mode)

    I tried using callbacks/wsDualHttpBinding but have some difficulty in getting this incorporated for all clients. So, had to drop this option.
    working on async/await. I have googled quite a few links but nothing helps with my problem.
    Please guide me on how to get the current/running value from a method that is not complete yet from a WCF service so I could populate the progress bar percentage based on this value. (in between values)
    P.S: WCF service uses wsHttpBinding
    sample code below:

    public Progress(){// Start the BackgroundWorker. myBGWorker.WorkerReportsProgress = true; myBGWorker.WorkerSupportsCancellation = false; myBGWorker.DoWork += myBGWorker_DoWork; myBGWorker.ProgressChanged += myBGWorker_ProgressChanged;}public void ShowProgress(){ myBGWorker.RunWorkerAsync();}private void myBGWorker_DoWork(object sender, DoWorkEventArgs e){// fetches a static value from the service string value = _client.Progress();int p=0;for (int i = 1; i <= 100; i++){// Report progress. p = Convert.ToInt32(_client.Progress()); _logger.Debug("Progress5:" + p.ToString()); myBGWorker.ReportProgress(p, i);}}private void myBGWorker_ProgressChanged(object sender, ProgressChangedEventArgs e){this.Dispatcher.BeginInvoke(new Action(delegate{ progressBar1.Value = e.ProgressPercentage;}), DispatcherPriority.ContextIdle);}

  2. Martin Ivanov
    Martin Ivanov avatar
    2215 posts

    Posted 09 May 2017 Link to this post

    Hello Kani,

    I used your code and it seems that the progress bar is updated properly. However, if the logic in the DoWork() is executed very fast, you won't the progress update, but the bar will be filled instantly. I modified a bit your code to sleep the thread at each iteration of the loop and the progress changes are noticeable. You can see this in the attached project.

    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top