• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1991
  • Last Modified:

Create dialog box with progress bar and button

Hi Expert,
I have a lenghtly process ( retrieve data from MySql and do some calculations) I'd like
while I am processing data, I can use a pop up dialog box where there is progress bar
to monitor the ongoing proces, and a CAncel button that uer can abort the process if it
takes too long.
Could you how to implement this task?
Thanks,
JT
0
jtran007
Asked:
jtran007
  • 4
  • 3
1 Solution
 
CuteBugCommented:
First of all you need to perform your lengthy task using BackgroundWorker

http://dotnetperls.com/backgroundworker
http://msdn.microsoft.com/en-us/library/cc221403%28VS.95%29.aspx

Based on the progress reported by the background worker you can update the progress bar of your dialog box.

Background worker also supports cancellation.
0
 
jtran007Author Commented:
Hi Expert,

Thanks How do I use progessba to report the status of background task, and use cancel button to
cancel background task
Since I am new to c#, please help

JT
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jtran007Author Commented:
Hi Expert,

I use ThreadPool to create a number of threads on the fly. I don't know how to link
progress bar with threadpool ; with separate thread I know how to do.

Thanks,
JT
0
 
CuteBugCommented:
I have provided a sample code where you can use the threadpool to update the progress bar value
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            WaitCallback workItem = new WaitCallback(ProcessWork);

            ThreadPool.QueueUserWorkItem(workItem, new SetProgressDelegate(SetProgressValue));
        }

        static void ProcessWork(object param)
        {
            SetProgressDelegate p = param as SetProgressDelegate;

            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(500);
                p(i);
            }
        }

        private delegate void SetProgressDelegate(int progress);

        private void SetProgressValue(int progress)
        {
            if (myProgressBar.InvokeRequired)
            {
                myProgressBar.Invoke(new MethodInvoker(
                    delegate
                    {
                        SetProgressValue(progress);
                    }
                ));
            }
            else
                myProgressBar.Value = progress;
        }
    }
}

Open in new window

0
 
jtran007Author Commented:
Hi Expert,

Thanks for sample code. It's working perfectly.
If I put a Cancel button to allow user to cancel the thred pool if it takes too
long (some problem with dtabase). How can it send envent to trhread pool.
Could you give me a sample example  too?

Thanks for your help.
JT
0
 
jtran007Author Commented:
Hi Expert,

I have two questions:
1- Can I use both Background Worker and ThreadPool at the same time?
2- While usign ThreadPool, I create thousands small threads taks that queries
some data from Mysql, the problem is that I have maximum 25 ManualEvents allowed
to use. Is there other ways  rather than use ManualEvent? Since each my small thread
queries data and do some calculation, and save it to its state. When all threads finish
calculations, I display their results in datagridview.

I am looking forward to your help.
Thanks,
JT
0
 
Alan HardistyCo-OwnerCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now