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

Posted on 2011-05-12
Last Modified: 2012-05-11
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 Customerthread = new Thread(new ThreadStart(GetCustomerDetails));

        private void loadbar()
            progressBar1.Minimum = 1;
            progressBar1.Maximum = 25;            
            progressBar1.Value = 1;
            progressBar1.Step = 1;
            for (int i = 0; i < 25; i++)
            CustomerList cList = new CustomerList(ListValues);
        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.
Question by:ziorinfo
    LVL 10

    Accepted Solution

    so this is a fat client/windows app?

    if so:

                // This causes an exception since ThreadNameHere is sleeping.
            catch(ThreadStateException stateException)
                Console.WriteLine("\n{0} caught:\n" +
                    "Thread is not in the Unstarted or Running state.",
                Console.WriteLine("ThreadState: {0}, ApartmentState: {1}",
                    ThreadNameHere.ThreadState, newThread.GetApartmentState());
    LVL 10

    Expert Comment

    oups... switch newThread on last line for ThreadNameHere

    Author Closing Comment

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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now