473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

update ProgressBar

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
Dec 13 '06 #1
2 2920
An oldy that you could ugrade to .net 2.0

http://www.eggheadcafe.com/articles/...ous_events.asp

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"Rico Schäpe" <ne**********@hoffrichter.dewrote in message
news:dt************@slox.hoffrichter.de...
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
Dec 14 '06 #2
use a backgroundworker to wrap your long running process. see
http://msdn2.microsoft.com/de-de/lib...er(VS.80).aspx

Dec 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
Hi all, continued from yesterday's posting... I still haven't found a solution to this issue. I put a breakpoint in private void SqlBackupPercentComplete(string message, int Percent) {...
1
by: | last post by:
Hi all I am posting this to check if anyone could help me. The problem still persists. I am beginner in C#. Thanks. Subject: SQLDMO.Backup and ProgressBar - help please From: ...
2
by: jez123456 | last post by:
Hi, thanks for the previous advice on progressbars with showing the percentage. I would now like to create a less clunky version. I.e at the moment my progressbar shows 7 separate steps. Some...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
0
by: Rick | last post by:
I use VB .Net and try to do som intensive actions on a database (in a seperate module). I defined an Interface for updating a progressbar on the main form. When I test it from a procedure within...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
2
by: DragonLord | last post by:
How do you update a progress bar on your main form from another class int he project (C#)
5
by: =?Utf-8?B?R3V5IENvaGVu?= | last post by:
Hi all I use vb.net 2005 Lets say I have the handle number of a progress bar from program1.exe Can I change the value of the progress bar from program2.exe using this handle number? TIA Guy...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.