I am trying to update a progressbar using the dispatcher but somehow cannot think where to place the dispatcher.Invoke and what to pass inside it.
Im trying to import files and needs to show the user how many files are imported using the progress bar.
so I have a delegate:
public delegate void DelegateA(ProgressClass progressClass);
im calling the delegate and passing the function to call.
DelegateA(FunctionA);
so while importing each file it calls the FunctionA.
private void FunctionA(ProgressClass progressClass)
{
**//Put dispatcher.invoke here?**
progressbar.updateprogress(progressclass);
progressbar.show();
}
The progressclass has two properties which sets the progressbar's value(how many have been processed) and total items to process.
I can't understand what delegate method to pass in InvokeMethod(THreadPriority, delegate method)?
Sorry, if something is not clear.
If you are trying to update the UI from some non-UI thread you can do something like this..
This code is taken from a good post about updating UI from background thread
I am assuming that you've started a background thread to import the files. You should consider using BackgroundWorker for this, which is lightweight and has a mechanism built in to report progress (e.g., a ProgressBar) using an event.
If you want to use a new thread, anywhere within the processing that you are doing, just declare a delegate, add a function to target, and call Dispatcher.BeginInvoke:
Here is the code for CSV reader with progress bar
private void InsertCSVRecords(DataTable csvdt) {