locked
How to increment a progress bar from another project? RRS feed

  • Question

  • I have created a class library project that mines a database for business opportunities and populates various data structures. I am currently using a simple Windows Form project to display the results. The main form has a progress bar that I would like to control from the data mining class.

    The snag is that I don't want to refer explcitly to the form (or its progress bar) in my data mining class, because the class may be implemented with different (or even multiple) front ends in future. Can I create some kind of messenger class that my data mining class writes to, and have my front end poll it for progress bar input?

    Thanks for any brilliant ideas!

    - Al

    Friday, January 14, 2011 1:33 AM

Answers

  • Do something like BackgroundWorker.ReportProgress, raise an event and pass the state in event arguments.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Proposed as answer by Konrad Neitzel Monday, January 17, 2011 5:55 AM
    • Marked as answer by Paul Zhou Wednesday, January 19, 2011 5:55 AM
    Friday, January 14, 2011 2:08 AM
  • Hi AllenN,

    I agree Sheng Jiang's meaning,you can use the control named BackgroundWorker.

    1.You can create the BackgroundWorker programmatically or you can drag it  onto your form from the Components tab of the Toolbox.

    2.Call RunWorkerAsync() of the BackGroundWorker In a function.

    3.This function is a asynchronous operation , automatically excute the event of BackGroundWork's DoWork.

    4.Call the function of ReportProgress() will excute ProgressChanged event.

    Link to:http://msdn.microsoft.com/en-au/library/system.componentmodel.backgroundworker.aspx.

    I hope you can find the way.

    • Marked as answer by Paul Zhou Wednesday, January 19, 2011 5:55 AM
    Monday, January 17, 2011 10:05 AM

All replies

  • Do something like BackgroundWorker.ReportProgress, raise an event and pass the state in event arguments.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Proposed as answer by Konrad Neitzel Monday, January 17, 2011 5:55 AM
    • Marked as answer by Paul Zhou Wednesday, January 19, 2011 5:55 AM
    Friday, January 14, 2011 2:08 AM
  • Thanks, Sheng Jiang.

    I don't know how to do that, yet (haven't got far enough in my C# book) but I'll have a go.

    - Al

    Sunday, January 16, 2011 11:33 PM
  • Hi AllenN,

    I agree Sheng Jiang's meaning,you can use the control named BackgroundWorker.

    1.You can create the BackgroundWorker programmatically or you can drag it  onto your form from the Components tab of the Toolbox.

    2.Call RunWorkerAsync() of the BackGroundWorker In a function.

    3.This function is a asynchronous operation , automatically excute the event of BackGroundWork's DoWork.

    4.Call the function of ReportProgress() will excute ProgressChanged event.

    Link to:http://msdn.microsoft.com/en-au/library/system.componentmodel.backgroundworker.aspx.

    I hope you can find the way.

    • Marked as answer by Paul Zhou Wednesday, January 19, 2011 5:55 AM
    Monday, January 17, 2011 10:05 AM