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 7975221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:35:33+00:00 2026-06-04T08:35:33+00:00

I am currently attempting to implement an auto-save feature on test software. The Start

  • 0

I am currently attempting to implement an auto-save feature on test software.

The “Start” button fires off TestThread to do testing. The UI is updated via Invokes from TestThread to provide the tester with real time information on the test. When the user clicks the “Stop” button, a flag is set signalling TestThread to finish the current test and stop. It also disables controls on the UI and fires StopThread to monitor TestThread’s progress. When TestThread finishes, StopThread re-enables the UI controls.

At this point, I need to wait for StopThread to finish so the autosave (SaveFileDialog leading to Excel file generation) can be called. However, using StopThread.Join() in the “Stop” button click handler only seems to cause the program to hang. This is likely because TestThread takes time to finish and attempts to update the blocked UI thread.

Calling the save function from StopThread generates a ThreadStateException because I use the SaveFileDialog (modal form) and requires that the calling thread be set to “single thread apartment” apparently.

Searching on this seems to point to general answers on simply using Thread.Join(). The simple fact that I need to keep the UI active until the thread finishes makes this unusable. Is there a way to call the SaveFileDialog from StopThread but marshal it to the UI thread? Any other suggestions? Thanks in advance.

WORKING SOLUTION:

private void btn_Stop_Click(object sender, EventArgs e)
    {
        //Disable UI controls and flag test ending

        Thread StopThread = new Thread(WaitForTestEnd);
        StopThread.Start();        
    }

    private void WaitForTestEnd()
    {
        while (!testStopped) //Flag set at end of TestThread
        {
            Thread.Sleep(50);
        }

        //Re-enable UI

        AutoSave saveMyData = SaveData;
        Invoke(saveMyData);
    }

    private delegate void AutoSave();

    private void SaveData()
    {
        //Generate SaveFileDialog and save.
    }
  • 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-04T08:35:34+00:00Added an answer on June 4, 2026 at 8:35 am

    Don’t block on StopThread at all. Instead arrange that StopThread signals the main thread that it has finished. For example by using Invoke.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently attempting to implement a custom gridview interface to display data from
I am currently attempting to implement a regular expression engine. (Yes, for fun. Go
We're currently attempting to implement a sql server 2008 udf to do expansion of
I'm attempting to implement a MVP pattern in my latest project. Currently using the
I'm currently attempting to implement having a (signed) applet communicate to a server program
currently I'm attempting to basically implement and exact copy of Apples iMessage App. That
I'm currently attempting to implement APC caching as a datastore in my web application.
I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt.
I am currently attempting to use Lucene to search data populated in an index.
I'm currently attempting to code one for part of a college project - binary/hex

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.