Link to home
Start Free TrialLog in
Avatar of Mahesh Yadav
Mahesh YadavFlag for India

asked on

Abort the current thread and redirect to another page : windows application

I am working on a windows application in which i had created two new threads, one is for progress bar and another is for extracting data from db. What i want is when the second thread is completed, it will terminate the first thread and autoredirect the page to another page. I am able to redirect to another page but as the threads are running it returns back to first page.

Here is my code:
 private void LoadingForm_Load(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(loadbar));
            CheckForIllegalCrossThreadCalls = false;
            thread.Start();
            Thread Customerthread = new Thread(new ThreadStart(GetCustomerDetails));
            Customerthread.Start();
        }

        private void loadbar()
        {
            progressBar1.Minimum = 1;
            progressBar1.Maximum = 25;            
            progressBar1.Value = 1;
            progressBar1.Step = 1;
            for (int i = 0; i < 25; i++)
            {
                System.Threading.Thread.Sleep(500);
                progressBar1.PerformStep();      
            }
            CustomerList cList = new CustomerList(ListValues);
            cList.Show();
        }
        private void GetCustomerDetails()
        {
// Code to get data from db.
         }


Here the control goes to customerlist page but returns back after running its constructor.

Please advice.
ASKER CERTIFIED SOLUTION
Avatar of MaxOvrdrv2
MaxOvrdrv2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MaxOvrdrv2
MaxOvrdrv2

oups... switch newThread on last line for ThreadNameHere
Avatar of Mahesh Yadav

ASKER

The given solution is not specifying the exact solution for the question asked.