Hi,
In my VB6 application I'm using a class/object that is using full-async ADO.
I can start multiple queries, the class stores the ADODB.Recordset object in
an array and waits for the QueryComplete event. This will set the result and
flag 'the query is finished' in the array.
In my WaitForResult() method I wait till the flag 'query is finished' is set
and return to the caller. While waiting I'm calling DoEvents and delay
function to prevent blasting the CPU so my VB6 application keeps responding
(pseudo code at the end of this posting).
In .NET I want to create about the same object as in VB and prevent
application to hang during long running queries. From a MDI application I
want to be able to run multiple queries at the same time.
One advantage is that in C# I'm be able to use threads, I'm using them in
C++ project too, but I'm not sure this is the best way to go. Using events
is IMO not a good approach because I should break-up my code when retrieving
some data.
When using threads I can use a semaphores or event handlers, but while
waiting them my application will block. Seems te be no other way then
calling a messagepump while waiting, is there a preffered way to do this in
..NET?
Another idea is split up the code for queries that almost return immediately
(run in same thread/blocking) and long running queries (creates another
thread/non-blocking).
What is a good approach for writing such class around ADO.NET? And what is a
good approach to prevent desktop applications from blocking?
TIA,
Rene
In pseudo code:
If class.QuerySomething ("Select bla bla" ) Then
' Query successful
Else
' Report error class.GetLastErrMSg()
class.QuerySomething ( Query, Parameters )
Declare rs as new ADODB.Recordset
Open query
QuerySomething = WaitForResult (rs)
class.WaitForResult ( rs )
index = StoreInArray (rs)
While not QueryComplete (index)
DoEvents
' Some other stuff
Wend
WaitForResult = GetResults (index)
FreeObjectInArray (index)
p.s. please note that using this way of programming has a lot of pitfalls,
all forms keeps responding so you must prevent re-entrance of events.