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

  • Home
  • SEARCH
  • 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 4609580
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:00:29+00:00 2026-05-22T01:00:29+00:00

My WinForm apps needs to execute complex query with significant execution time, I have

  • 0

My WinForm apps needs to execute complex query with significant execution time, I have no influence (about 10mins)
When query is executing user sees ‘application not responding’ in task manager, which is really confusing to user, also not very professional…

I believe that query shall be executed in different thread or so. Have tried some approaches but have difficulties to make it really working (execute query, force main application wait result, return back to main app, possibility to cancel execution etc)

I wonder if you have own / good working solution for that. Code samples would be also very welcome 🙂

Also I believe there might exist some ready to use utilities / frameworks allowing simple execution of that.

  • 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-05-22T01:00:30+00:00Added an answer on May 22, 2026 at 1:00 am

    If ExecuteQuery if the method you want to execute, you can do:

    void SomeMethod() {
        var thread = new Thread(ExecuteQuery);
        thread.Start();
    }
    
    void ExecuteQuery() {
        //Build your query here and execute it.
    }
    

    If ExecuteQuery receives some parameters, like:

    void ExecuteQuery(string query) {
        //...
    }
    

    You can do:

    var threadStarter = () => { ExecuteQuery("SELECT * FROM [Table]"); };
    var thread = new Thread(ThreadStarter);
    thread.Start();
    

    If you want to stop the execution of the background thread, avoid calling thread.Abort() method. That will kill the thread, and you do not want this, because some incosistency could appear in your database.

    Instead, you can have a bool variable visible from ExecuteQuery and from outside you can set it to True when you want to stop it. Then all you have to do is check in some parts of the code inside ExecuteQuery if that variable is still True. Otherwise, do some rollback to maintain the database stable.

    Be sure you set that bool variable volatile

    Edit:
    If you want the UI to wait from the background thread, I usually do:

    • Start the background thread
    • Start some progress bar in the UI
    • Disable some controls (like buttons, etc) to avoid the user to click them while the background thread is working (eg: If you’re executing the thread when a user clicks a button, then you should disable that button, otherwise multiple queries will be ocurring at the same time).

    After finished the thread, you can stop progress bar and enable controls again.

    How to know when the thread finished? You can use Events for that. Just create an event and fire it when it finishes, and do whatever you want inside the event handler…

    Be sure you’re accessing correctly to UI controls from the background thread, otherwise it will give you an error.

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

Sidebar

Related Questions

Our team develops distributed winform apps. We use ClickOnce for deployment and are very
I'm trying to get better at using MVC/MVP style patterns with my WinForm apps
so i have a winforms apps that downloads a set of data syncronously on
I have a winform app that calls a web service to check for updates.
I have a Winform application built with C# and .Net 2.0. I have a
I have my winform application gathering data using databinding. Everything looks fine except that
BACKGROUND I've successfully embedded IronPython in my WinForm apps using techniques like the one
We are developing a .NET 2.0 winform application. The application needs to access Web
I have in the past coded up Windows Form or Console apps in Visual
I am writing a simple framework for testing WinForm apps, which is running in

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.