This is a migrated thread and some comments may be shown as answers.
Progress Bar in WPF application for long running WCF service
1 Answer 11 Views
This is a migrated thread and some comments may be shown as answers.
Aria
Top achievements
Rank 1
Aria asked on 05 May 2017, 04:46 AM

 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);}

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 09 May 2017, 03:29 PM
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.

Regards,
Martin
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.
Asked by
Aria
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or