A
Angelo
Hello,
I am currently working on a small project which performs user defined
queries on an MS-SQL DB. When the user starts the query, I start a
temporary thread (thread pool) which performs the query and contacts
the UI thread when the data is ready, which is then displayed.
I would like to allow the user to abort a query while its processing,
but I seem to be having trouble on how to implement the abort
mechanism. This is due to the fact that most of the time spent in the
query thread is waiting for the database connection to retrieve all of
the row data.
Currently, I have thought of three solutions:
1. Create a flag in the query thread which tells it to cancel the
query. The thread would only check this flag directly before the
query is executed and directly after. If the user decides to cancel
the query while the thread is waiting on the database connection, then
the thread will continue until all data is retrieved, but the data
will not be displayed.
2. Similar to 1, create a flag in the query thread which tells it to
cancel the query. In the query thread, create a loop which only
queries part of the data each time, checking the flag on each
iteration (for example, 10 iterations of 3000 rows per iteration).
3. Abort the thread (which I have read countless number of time is
evil).
I believe that 2 is the best solution, however I have not come up with
a sufficient implementation. Currently, this project is using Linq to
SQL / Entity Classes to obtain the data from the database. Is there a
'simple' way to splice a query into a defined number of chunks for
retrieval?
For simplicity's sake, lets say the table I am querying from is
defined as such:
Table Name: Process_Output
Columns -
ID <pk> long
Name NText
Value int
Timestamp Date
My inexperience in the area is definitely a hindrance, therefore I am
looking to a few experts for some helpful advice. If you need more
information, I will gladly provide.
Thanks
AJ
I am currently working on a small project which performs user defined
queries on an MS-SQL DB. When the user starts the query, I start a
temporary thread (thread pool) which performs the query and contacts
the UI thread when the data is ready, which is then displayed.
I would like to allow the user to abort a query while its processing,
but I seem to be having trouble on how to implement the abort
mechanism. This is due to the fact that most of the time spent in the
query thread is waiting for the database connection to retrieve all of
the row data.
Currently, I have thought of three solutions:
1. Create a flag in the query thread which tells it to cancel the
query. The thread would only check this flag directly before the
query is executed and directly after. If the user decides to cancel
the query while the thread is waiting on the database connection, then
the thread will continue until all data is retrieved, but the data
will not be displayed.
2. Similar to 1, create a flag in the query thread which tells it to
cancel the query. In the query thread, create a loop which only
queries part of the data each time, checking the flag on each
iteration (for example, 10 iterations of 3000 rows per iteration).
3. Abort the thread (which I have read countless number of time is
evil).
I believe that 2 is the best solution, however I have not come up with
a sufficient implementation. Currently, this project is using Linq to
SQL / Entity Classes to obtain the data from the database. Is there a
'simple' way to splice a query into a defined number of chunks for
retrieval?
For simplicity's sake, lets say the table I am querying from is
defined as such:
Table Name: Process_Output
Columns -
ID <pk> long
Name NText
Value int
Timestamp Date
My inexperience in the area is definitely a hindrance, therefore I am
looking to a few experts for some helpful advice. If you need more
information, I will gladly provide.
Thanks
AJ