473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Asynchronous Delegate Question

In the application I am working on, the user makes a request of information
from the database. As there is a great deal of information to go through and
possibly return, to speed things up, the request for data only returns the
first 25 rows of data. So thas the user knows how many total rows of data
there are, a count is returned by another stored procedure. This query can
take a while to complete so I have created a delete called ProductCount that
I call asynchronously. The problem comes when the user changes their mind on
which item's information he wants to view. I need to cancel the previous call
to ProductCount and initiate the new call to ProductCount. The code looks
something like this:

public delegate void CountDelegate (string[] params);
private CountDelegate cDeleg;

public GetInfo ()
{
DataSet ds = GetProductResults (string params, int startIndex, int
numRowsReturn);

//not another page of current query results so count does not need to be
//computed again
if (newQuery)
{
cDeleg = new CountDelegate (ProductCount);
AsyncCallback cb = new AsyncCallback (CountCallback);
cDeleg.BeginInvoke(params, cb, "CountDelegate");
}
}

public void ProductCount (string[] params)
{
int records = GetProductCount (params); //call to stored procedure

//do some stuff with the record count
}

private void CountCallback (IAsyncResult ar)
{
cDeleg.EndInvoke (ar);
}

As it is the stored procedure part that takes the time to run and not the
code, how to I gracefully cancel so I can start the new query? I have tried
adding a parameter in ProductCount to check to see if the ending thread is
the same as the current thread number, but there is a race condition so the
index has changed in the middle of that function. I got the idea of the index
from the boolean examples I saw. I do not want to hold up the user interface
waiting for the long process to come back before starting the next get
product query. We are using Oracle so I do invoke the OracleCommand.Cancel,
but that can take a while as well. We are really trying to decrease response
time and the count is a major eater of time. Guestimating the count is not
usable because of the table structure so the count as been off by an order of
2. Any ideas?

Thank you,
Susan
Aug 11 '06 #1
7 3557
I prefer not to just leave the process running on the database since
resources can be valuable.

"Susan" wrote:
In the application I am working on, the user makes a request of information
from the database. As there is a great deal of information to go through and
possibly return, to speed things up, the request for data only returns the
first 25 rows of data. So thas the user knows how many total rows of data
there are, a count is returned by another stored procedure. This query can
take a while to complete so I have created a delete called ProductCount that
I call asynchronously. The problem comes when the user changes their mind on
which item's information he wants to view. I need to cancel the previous call
to ProductCount and initiate the new call to ProductCount. The code looks
something like this:

public delegate void CountDelegate (string[] params);
private CountDelegate cDeleg;

public GetInfo ()
{
DataSet ds = GetProductResults (string params, int startIndex, int
numRowsReturn);

//not another page of current query results so count does not need to be
//computed again
if (newQuery)
{
cDeleg = new CountDelegate (ProductCount);
AsyncCallback cb = new AsyncCallback (CountCallback);
cDeleg.BeginInvoke(params, cb, "CountDelegate");
}
}

public void ProductCount (string[] params)
{
int records = GetProductCount (params); //call to stored procedure

//do some stuff with the record count
}

private void CountCallback (IAsyncResult ar)
{
cDeleg.EndInvoke (ar);
}

As it is the stored procedure part that takes the time to run and not the
code, how to I gracefully cancel so I can start the new query? I have tried
adding a parameter in ProductCount to check to see if the ending thread is
the same as the current thread number, but there is a race condition so the
index has changed in the middle of that function. I got the idea of the index
from the boolean examples I saw. I do not want to hold up the user interface
waiting for the long process to come back before starting the next get
product query. We are using Oracle so I do invoke the OracleCommand.Cancel,
but that can take a while as well. We are really trying to decrease response
time and the count is a major eater of time. Guestimating the count is not
usable because of the table structure so the count as been off by an order of
2. Any ideas?

Thank you,
Susan
Aug 11 '06 #2
You really don't have another option except for spinning off another
thread while waiting for the current one to complete/cancel. How much
tuning have you done for the query? If you want to post an explain plan
and statistics for the query in question we might be able to suggest
improvements there.

Aug 11 '06 #3
The database has over 30 million products in it so you can tune only so much.
We have a lot of security restrictions in the query. Our DBA (sjipped in from
Oracle) has optimized it the best he can. He was hoping to get the estimated
count to work, but it was off too much. I could always turn it from a
delegate to a thread, and then send the cancel command to Oracle before
aborting teh thread. I was just hoping for a more graceful end. :)

Thank you,
Susan

"wf****@gmail.com" wrote:
You really don't have another option except for spinning off another
thread while waiting for the current one to complete/cancel. How much
tuning have you done for the query? If you want to post an explain plan
and statistics for the query in question we might be able to suggest
improvements there.

Aug 11 '06 #4
30 million records isn't a very large amount but if you trust that your
DBA has properly tuned/organized the database then there's no reason to
investigate further. How was he going about retrieving the "estimated"
count? Was he checking the cardinality from the explain plan?
Don't abort the thread, just let it finish gracefully in the
background while you run the new/next query from a different thread.

Susan wrote:
The database has over 30 million products in it so you can tune only so much.
We have a lot of security restrictions in the query. Our DBA (sjipped in from
Oracle) has optimized it the best he can. He was hoping to get the estimated
count to work, but it was off too much. I could always turn it from a
delegate to a thread, and then send the cancel command to Oracle before
aborting teh thread. I was just hoping for a more graceful end. :)

Thank you,
Susan

"wf****@gmail.com" wrote:
You really don't have another option except for spinning off another
thread while waiting for the current one to complete/cancel. How much
tuning have you done for the query? If you want to post an explain plan
and statistics for the query in question we might be able to suggest
improvements there.
Aug 11 '06 #5
You might want to look into having a separate table that gets updated by a
trigger or other mechanism that maintains your counts. Could be one heck of a
lot faster,no ?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Susan" wrote:
The database has over 30 million products in it so you can tune only so much.
We have a lot of security restrictions in the query. Our DBA (sjipped in from
Oracle) has optimized it the best he can. He was hoping to get the estimated
count to work, but it was off too much. I could always turn it from a
delegate to a thread, and then send the cancel command to Oracle before
aborting teh thread. I was just hoping for a more graceful end. :)

Thank you,
Susan

"wf****@gmail.com" wrote:
You really don't have another option except for spinning off another
thread while waiting for the current one to complete/cancel. How much
tuning have you done for the query? If you want to post an explain plan
and statistics for the query in question we might be able to suggest
improvements there.
Aug 12 '06 #6
Seems to be a complex model, prone with potential issue. As you call count
anyway, it seems to me you should return count in the stream with the first
25 records. Then they know how many and you don't need another round trip to
the server, or worry about canceling the first call.

--
William Stacey [MVP]

"Susan" <Su***@discussions.microsoft.comwrote in message
news:E2**********************************@microsof t.com...
| In the application I am working on, the user makes a request of
information
| from the database. As there is a great deal of information to go through
and
| possibly return, to speed things up, the request for data only returns the
| first 25 rows of data. So thas the user knows how many total rows of data
| there are, a count is returned by another stored procedure. This query can
| take a while to complete so I have created a delete called ProductCount
that
| I call asynchronously. The problem comes when the user changes their mind
on
| which item's information he wants to view. I need to cancel the previous
call
| to ProductCount and initiate the new call to ProductCount. The code looks
| something like this:
|
| public delegate void CountDelegate (string[] params);
| private CountDelegate cDeleg;
|
| public GetInfo ()
| {
| DataSet ds = GetProductResults (string params, int startIndex, int
| numRowsReturn);
|
| //not another page of current query results so count does not need to be
| //computed again
| if (newQuery)
| {
| cDeleg = new CountDelegate (ProductCount);
| AsyncCallback cb = new AsyncCallback (CountCallback);
| cDeleg.BeginInvoke(params, cb, "CountDelegate");
| }
| }
|
| public void ProductCount (string[] params)
| {
| int records = GetProductCount (params); //call to stored procedure
|
| //do some stuff with the record count
| }
|
| private void CountCallback (IAsyncResult ar)
| {
| cDeleg.EndInvoke (ar);
| }
|
| As it is the stored procedure part that takes the time to run and not the
| code, how to I gracefully cancel so I can start the new query? I have
tried
| adding a parameter in ProductCount to check to see if the ending thread is
| the same as the current thread number, but there is a race condition so
the
| index has changed in the middle of that function. I got the idea of the
index
| from the boolean examples I saw. I do not want to hold up the user
interface
| waiting for the long process to come back before starting the next get
| product query. We are using Oracle so I do invoke the
OracleCommand.Cancel,
| but that can take a while as well. We are really trying to decrease
response
| time and the count is a major eater of time. Guestimating the count is not
| usable because of the table structure so the count as been off by an order
of
| 2. Any ideas?
|
| Thank you,
| Susan
Aug 12 '06 #7
The count dpeends on a lot of factors (access to the record, filters he may
have on, etc.) so that would not be realistic. Otherwise, that would be a lot
easier. :)

Thanks,
Susan

"Peter Bromberg [C# MVP]" wrote:
You might want to look into having a separate table that gets updated by a
trigger or other mechanism that maintains your counts. Could be one heck of a
lot faster,no ?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Susan" wrote:
The database has over 30 million products in it so you can tune only so much.
We have a lot of security restrictions in the query. Our DBA (sjipped in from
Oracle) has optimized it the best he can. He was hoping to get the estimated
count to work, but it was off too much. I could always turn it from a
delegate to a thread, and then send the cancel command to Oracle before
aborting teh thread. I was just hoping for a more graceful end. :)

Thank you,
Susan

"wf****@gmail.com" wrote:
You really don't have another option except for spinning off another
thread while waiting for the current one to complete/cancel. How much
tuning have you done for the query? If you want to post an explain plan
and statistics for the query in question we might be able to suggest
improvements there.
>
>
Aug 14 '06 #8

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

Similar topics

6
by: ... | last post by:
Does anyone know a good tutorial on asynchronous programming in .net AsyncCallback And IASyncResult are driving me crazy. And the msdn documentation is not really helpful on this topic I...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
3
by: Oscar Thornell | last post by:
Hi, I am thinking about doing all my logging asynchronously using a delegate. The main resaon for this would be performance and responsiveness of the application (an ASP.NET app). //Exampel...
3
by: Stewart | last post by:
Hey Group, Hoping someone can help me out. I have some code which starts up some asynchronous code using a delegate. The code is below. Basically my main code (not shown) calls...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
1
by: dba123 | last post by:
I need to perform Asynchronous Inserts using DAAB. So far I have a method which does an insert but how can I do this Asyncronously so that it does not affect the load on our public production...
4
by: 6954 | last post by:
Hi! i need to implement some asynchronous call to my com+ component, but i need it to return some values (e.g. results of sql select statement). obviously queued components and MSMQ are out of...
3
by: =?Utf-8?B?bWs=?= | last post by:
Hi everyone, I need to refactor some of our processes using the asynchronous programming model. I have defined a couple of arrays of delegates to pipline the asynchronous invocations through...
4
by: MaxMax | last post by:
I'm using HttpWebRequest. It seems that all the callback called from HttpWebRequest are in another thread (not in the "original" thread). Now my problem is that the "original" thread is the thread...
3
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I need to write asynchronous HTTPModule which will sometimes execute long job. I've written it using AddOnBeginRequestAsync but it still executes synchronously - I am checking performance...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.