Session.BreakExecution, multithread

vkupisk

Member
I don't have any experience with multithreaded apps., but i'd like to give my users an opportunity to kill a long-running query without killing the whole app, just adding a "break" button to kill whatever query is running at the moment. After an hour of spinning my wheels -- can anyone give me a hint?
 
If you are using a TOracleQuery to perform this query, set Threaded to True, and call BreakThread to cancel it. See documentation on Threaded property for details.

------------------
Marco Kalter
Allround Automations
 
That's great, if you are using a TOracleQuery. But what would be the best way to do this using a TOracleDataset?

I would like a message box to pop up while the query is running, with a single cancel button on it, and disappear as soon as the query is finished. Ideally I would like this to be included in the TOracleDataset, with two properties to set:
a) a boolean to specify wheter the dialog box should show up, and
b) a label to be displayed in the dialog box (with a default value)

If the dialog box appears, the cursor property should be discarded (you don't want the user to have a dialog box with an hourglass cursor).

Would you consider including this functionality in your next release? I am sure I am not the only one to welcome this. If anyone has written some code already to handle this, I would also be happy to get some advice / code examples on how to achieve this.

[This message has been edited by helene (edited 21 April 2002).]
 
A TDataSet doesn't really allow background processing, though you can of course open a dataset in a backgound thread. See dsthread.zip for an example.

------------------
Marco Kalter
Allround Automations
 
Originally posted by mkalter:
A TDataSet doesn't really allow background processing, though you can of course open a dataset in a backgound thread.


Thanks for the example code, but unfortunatly I am still uncertain as to wheter it is possible to do what I need to do? Executing the SQL in a separate thread is one thing, but what I really need is the ability for the user to break the execution from a cancel button. Because we need this in reports built using reportBuilder and forms that use data aware components, we cannot use a TOracleQuery instead of a TOracleDataset.

Even if I open the dataset from a separate thread I haven't been able to find a way to break the execution before it is finished. When looking at the code used for TOracleQuery in the TQueryThread.Execute method (Oracle.pas), there is an execution loop which checks regularly wheter the execution has been broken. I don't see how I can do the same thing for a dataset?
 
If the TOracleDataSet is executing the SQL, a TOracleSession.BreakExecution will lead to a "ORA-01013, user requested cancel of current operation" and the dataset will not be opened.

If the TOracleDataSet is already fetching records, you could perform a "break" check in the AfterFetchRecord event handler, and cancel the fetch process.

I guess we should enhance the example...

------------------
Marco Kalter
Allround Automations
 
Thanks a lot, now it works absolutely GREAT! The users will be happy
smile.gif


Adding an example of this in the demo / a mention of it in the documentation would be a good idea.

I noted your reply in another question regarding threads and TOracleDataset, however:
"The dataset/datasource/datacontrols combination is not thread safe. You cannot open a dataset in a thread when it is connected to a datasource. You need to disconnect it from the datasource, open it in a thread, and after the thread is finished, reconnect it to the datasource."

I have done nothing with the datasource connection, but it still seems to work just fine?

With regards
Helene

[This message has been edited by helene (edited 18 June 2002).]
 
Back
Top