• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

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.
0
ziorinfo
Asked:
ziorinfo
  • 2
1 Solution
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now