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
jtran007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.