Hi,
I want to show a progress dialog for long working tasks. The task should
be canceled too. Inspired by the article of Chris Sells "Safe, Simple
Multithreading in Windows Forms, Part 2" I've worked on.
I want to use this progress dialog from any long working task. So I
don't want to have any GUI code inside the code data handling(model).
That's why I fired a progress event in my model which should update the
progress dialog.
But the problem is, that the progress dialog will not be updated.
I start the working task in an extra thread like described in the article:
delegate void WorkerDelegate();
WorkerDelegate worker = new WorkerDelegate(threadingEventsRead);
worker.BeginInvoke(null, null);
private void threadingEventsRead() {
m_deviceModel.readEvents();
}
The GUI itself have to update it's contents with the GUI main thread.
That's why I make an Control.Invoke() call:
delegate void ShowProgressDelegate(string task, int maxProgress, int
currentProgress);
public void onNotification(IEventPublisher publisher, EventArgs args) {
ProgressEventArgs progressArgs = args as ProgressEventArgs;
if (progressArgs != null) {
showProgress(progressArgs.ProgressState.Task,
progressArgs.ProgressState.Total,
progressArgs.ProgressState.Current);
}
}
private void showProgress(string task, int maxProgress, int
currentProgress) {
if (!m_viewer.InvokeRequired) {
m_viewer.ProgressDialog.setCurrentTask(task);
m_viewer.ProgressDialog.CurrentStep = currentProgress;
m_viewer.ProgressDialog.MaxStep = maxProgress;
} else {
ShowProgressDelegate showProgressDelegate = new
ShowProgressDelegate(showProgress);
m_viewer.Invoke(showProgressDelegate, new object[] {task,
maxProgress, currentProgress});
}
}
Like I said, the progress dialog popup but don't update it's progress. I
start all from the main form with:
private void menuReadEvents_Click(object sender, EventArgs e) {
m_mainController.readEvents();
m_progressDialog.ShowDialog();
}
Has anybody a hint how to solve this ?
Thanks in forward
Rico