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.
ziorinfoAsked:
Who is Participating?
 
MaxOvrdrv2Commented:
so this is a fat client/windows app?

if so:

try
        {
            // This causes an exception since ThreadNameHere is sleeping.
            ThreadNameHere.SetApartmentState(ApartmentState.STA);
        }
        catch(ThreadStateException stateException)
        {
            Console.WriteLine("\n{0} caught:\n" +
                "Thread is not in the Unstarted or Running state.",
                stateException.GetType().Name);
            Console.WriteLine("ThreadState: {0}, ApartmentState: {1}",
                ThreadNameHere.ThreadState, newThread.GetApartmentState());
        }
0
 
MaxOvrdrv2Commented:
oups... switch newThread on last line for ThreadNameHere
0
 
ziorinfoAuthor Commented:
The given solution is not specifying the exact solution for the question asked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.