Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7738481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:16:36+00:00 2026-06-01T08:16:36+00:00

I have a window(say main window) with a frame which has a page in

  • 0

I have a window(say main window) with a frame which has a page in it. A button on the page opens another window(say popup window). Now i am trying to invoke a method in the main window from a button on the popup window. The method has to be multi-threaded, i had a similar solution running in windows forms but i keep getting the calling thread must be STA because many UI components require this in WPF.

The method on the page which opens the popup window modally

Scripts showStocks = new Scripts();
            showStocks.ShowInTaskbar = false;
            showStocks.ShowDialog();
            if (showStocks.DialogResult==true)
            {
                Window1 wd1 = new Window1();
                wd1.doneDeal();
            }

Here window1 is our main window. The doneDeal method is

public void doneDeal()
        {
            // **Some Code**
            BackgroundWorker wworks1 = new BackgroundWorker();
            wworks1.DoWork += Tickes;
            wworks1.RunWorkerCompleted += Tickes2;
            wworks1.RunWorkerAsync();

           // Page1 pg1 = frame1.Content as Page1;
            //NextPrimeDelegate dd=new NextPrimeDelegate(okreport);
           // pg1.addScriptBtn.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
               // new NextPrimeDelegate(okreport));
            //startStopButton.Dispatcher.BeginInvoke(
                //    DispatcherPriority.Normal,
                //    new NextPrimeDelegate(CheckNextNumber));

            //new Thread(() => Tick(stock, rowID, exchange)) { IsBackground = false }.Start();


        }

Finally the method that i am trying to run in the background

public void Tickes(object sender, DoWorkEventArgs e)
        {

         }

Also i want to populate a gridview from the result of the tickes method, this will be looping and running over and over in the background but periodically returning data to be added to the grid. SHould i do that in the progress update event ? Have tried a lot to wrap my head around the dispatcher and background worker in wpf but am failing to understand the STA apartment state bit. If someone can help me to get my tickes method going or point me in the right direction, i would be very very thankful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:16:37+00:00Added an answer on June 1, 2026 at 8:16 am

    Well i finally was able to solve the STA thread problem am posting the answer just in case somebody comes across a similar problem in the future.

        public void doneDeal()
        {
            if (StockData.flag == 1)
            {
                row1 = table.NewRow();
                row1[col1] = "";
                row1[col2] = "";
                row1[col3] = "";
                row1[col4] = "";
                row1[col5] = "";
                row1[col6] = "";
                row1[col7] = "";
                row1[col8] = "";
                row1[col9] = "";
                row1[col10] = "";
                row1[col11] = "";
                row1[col12] = "";
                table.Rows.Add(row1);
                string stock = StockData.stock;
                int rowID = (table.Rows.Count - 1);
                string exchange = StockData.exchange;
                Thread bh = new Thread(delegate()
                {
                    Tick7(stock, rowID, exchange);
                });
                bh.SetApartmentState(ApartmentState.STA);
                bh.IsBackground = true;
                bh.Start();
                StockData.flag = -1;
            }
        }
    

    The Tick7 method which is being called is declared like this

        [STAThread]
        public void Tick7(string stock, int rowID, string exchange)
        {
    
            int rowNum = rowID;
            int counter = -1;
    
            deletecounter = StockData.deletecounter;
            Thread.CurrentThread.Name = StockData.stock;
            .
            .
            .
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a main page which has a link that opens a
Say, for instance, you have a popup which opens from your main page. The
In JavaScript, let's say we have a main page ( main.html ) which contains
I have 2 activities - Say Activity A and B. My main activity(A) has
I have a NIB which contains two windows, one is the app's main window
Say you have a Windows Mobile 6.0 phone that also has a GPS receiver.
I have a Window where I have put a Frame. I would like to
I have a Main Program which is running a script on the target device(smart
Let's say I've got a window for which I want to simulate a mouse
there i have created a program with a tab button and page number. all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.