472,993 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 software developers and data experts.

VB6 to C# .NET non-blocking ADO approach

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.

Nov 15 '05 #1
2 2213
Rene,

I believe that you are taking the wrong approach to this. Basically,
you should be using an event-based mechanism, instead of trying to mimic
responsiveness while waiting for a response. Basically, you should be
creating the other thread, and performing your work on that thread. Once
the work is done, you can send a notification to the UI thread for updating
(you don't have to worry about it being tied up), and then proceed from
there.

This is pretty much the model for any multi-threaded application. I
believe that the use of DoEvents in this situation is incorrect, and that
using a thread is the correct way to go. Yes, it breaks up your code, but
that shouldn't be a problem if you design your application correctly. Just
look at this as another step in the overall process. All of the steps don't
have to occur in the scope of one function call. If that was the case, we
would have these super-functions which would be quite unwieldly to use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rene" <no@spam.nl> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
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.


Nov 15 '05 #2

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> schreef
in bericht >

This is pretty much the model for any multi-threaded application. I
believe that the use of DoEvents in this situation is incorrect, and that
using a thread is the correct way to go.
The use of DoEvents in VB6 is the only way since VB6 is not multi-threading
and it is not possible to use ADODB Recordsets among processes. And nothing
worse then users hitting alt-ctrl-del because the application is not
responding.
Yes, it breaks up your code, but
that shouldn't be a problem if you design your application correctly.


Because the application would use a lot of forms and queries I'm afraid the
application can easily be messed-up when using threads and events for each
data-retrieval making the code hard to understand. There is a lot of classic
data-retrieval (open recordset, while not .eof addrecord/populate) that can
be done without using threads/events, so I will make a design that only for
long running queries threads will be used. This approach might lockup the
application very shortly in some situations when the server is very busy.

Is the ADO NextRecords() still available in .NET?

Rene


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
0
by: amitvps | last post by:
Secure Socket Layer is very important and useful for any web application but it brings some problems too with itself. Handling navigation between secure and non-secure pages is one of the cumbersome...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.