Skip to Content
author's profile photo Former Member
Former Member

DataTable ExecuteQuery Method Hanging the UI

Hi All,

I've got a relatively complex query that I'm running using the DataTable object's ExecuteQuery method to easily bind it to a Grid. No matter what I try (Timers, Background Threads, etc.), I can't seem to keep the UI from freezing up when I invoke this ExecuteQuery method (which takes ~3 minutes to run).

Is there some way of preventing this method from blocking the UI completely? I'd like to at least give the user a Status Bar message every few seconds or so to let him know the program is still doing work.

I have tried using a Windows Forms Timer, setting a Status Bar message on the Timer's Tick event, however the Tick event never seems to fire, as the application is stuck on the ExecuteQuery method call and it seems like the Application.DoEvents() method is never invoked.

I also tried setting a BackgroundWorker, but again, the call to ExecuteQuery is made in the background, and if I pause the add-on, it shows me it's stuck on a random line in the application (in reality it looks like ExecuteQuery is blocking the UI thread).

Any help would be greatly appreciated.

Thanks,

-Luis

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Apr 25, 2012 at 10:47 AM

    Hi Luis,

    When you use the ExecuteQuery method of the DataTable, the query will always be executed on the GUI thread, and therefore it will freeze the client.

    You have a couple of alternatives:

    1. Do not use the DataTable's ExecuteQuery method. Separate the GUI completely from the SQL action.
    2. Try to simplify the query
    3. Cut the query up into pieces, and only execute the piece that really must be executed right then and there with the ExecuteQuery method. Execute all other pieces on a completely separate thread.

    Regards,

    Johan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.