troubleshooting Question

Pass method name as a param? ThreadStart

Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America asked on
C#
2 Comments1 Solution639 ViewsLast Modified:
The code below does the following:

1)  Shows a windows form with a progressbar with style set to marquee (continuously runs).
2)  Creates and starts a thread which runs a lengthy process
3)  While that thread is alive I call DoEvents() so the progress bar form will refresh
4)  Lengthy process finishes, I display a message box.


My actual question is -- is there a way to make

            ThreadStart method = new ThreadStart(this.RunSQLAndDisplayResults);

more generic?  For example, pass in the method call in the ThreadStart constructor as a parameter?

Something like:  


private void RunSQL_Click(<method name or signature>)
{
...
...

            ThreadStart method = new ThreadStart(<method name or signature>);

...
...
}




private void buttonRunSQL_Click(object sender, EventArgs e)
        {
            WaitDialog wd = new WaitDialog();
            wd.Show();
            ThreadStart method = new ThreadStart(this.RunSQLAndDisplayResults);
            Thread thread = new Thread(method);
            thread.Start();

            while (thread.IsAlive)
            {
                System.Windows.Forms.Application.DoEvents();                
            }

            this.dataGridViewDataToExport.SuspendLayout();
            this.dataGridViewDataToExport.Columns.Clear();
            this.dataGridViewDataToExport.DataSource = this._sqldataset.Tables[0];
            this.dataGridViewDataToExport.ResumeLayout();

            labelCountOfItemsToExport.Text = "Row Count:  " + this._sqldataset.Tables[0].Rows.Count.ToString();

            MessageBox.Show("Data has been selected based on your preferences and is ready for export");

            wd.Hide();

        }
ASKER CERTIFIED SOLUTION
Tom Knowlton
Web developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros