ProgressBar incremented from outside of Form

M

mamin

I have, the following question:

I have a WindowsForm with ProgressBar progressBar1 and Button button1.
After onClick event on button the following method executes:

button_Click(object sender, EventArgs e)
{
DatabaseOperations.ClearDatabase();
}

where ClearDatabase() is static method which should increment my
progress bar. How can I increment my progress bar without giving
ProgressBar object as parameter( I mean without using
ClearDatabase(progressBar1); - it doesn't seem to be a good way)

Thanks for any reply.
 
J

Jon Skeet [C# MVP]

I have, the following question:

I have a WindowsForm with ProgressBar progressBar1 and Button button1.
After onClick event on button the following method executes:

button_Click(object sender, EventArgs e)
{
DatabaseOperations.ClearDatabase();
}

where ClearDatabase() is static method which should increment my
progress bar. How can I increment my progress bar without giving
ProgressBar object as parameter( I mean without using
ClearDatabase(progressBar1); - it doesn't seem to be a good way)

You'll need to provide *something*. If you want to decouple
DatabaseOperations from the UI (which is reasonable) you could give
DatabaseOperations a DatabasedClearProgress event which the UI could
subscribe to, and which ClearDatabase could raise.
 
M

mamin

You'll need to provide *something*. If you want to decouple
DatabaseOperations from the UI (which is reasonable) you could give
DatabaseOperations a DatabasedClearProgress event which the UI could
subscribe to, and which ClearDatabase could raise.


But how can I raise ProgressBar event from this static method?
 
J

Jon Skeet [C# MVP]

But how can I raise ProgressBar event from this static method?

You'd make the DatabaseClearProgress event static as well. It wouldn't
be a ProgressBar event - it would just be that the handler the UI added
would happen to update the progress bar.
 
T

Thomas T. Veldhouse

I have, the following question:

I have a WindowsForm with ProgressBar progressBar1 and Button button1.
After onClick event on button the following method executes:

button_Click(object sender, EventArgs e)
{
DatabaseOperations.ClearDatabase();
}

where ClearDatabase() is static method which should increment my
progress bar. How can I increment my progress bar without giving
ProgressBar object as parameter( I mean without using
ClearDatabase(progressBar1); - it doesn't seem to be a good way)

I think the issue is that ClearDatabase() should probably NOT be static. You
could create a database "engine" and then have an event on it to indicate
status, completion, what have you. Then subscribe to them from your UI and
have the event handler post to the progress bar.
 
J

Jon Skeet [C# MVP]

Thomas T. Veldhouse said:
I think the issue is that ClearDatabase() should probably NOT be static. You
could create a database "engine" and then have an event on it to indicate
status, completion, what have you. Then subscribe to them from your UI and
have the event handler post to the progress bar.

While I agree that it would be good to have a database engine instance,
there's nothing to stop the OP from having a static event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top