473,320 Members | 2,020 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,320 software developers and data experts.

PageAsyncTask Problem

I'm trying to set up a test asynchronously executing page that will
call a database stored procedure and then simply add text to a Label
control name mylabel However after executing the BeginEventHandler,
the EndEventHandler is not called and I have no idea why any help is
appreciated. My .aspx file is minimal the only thing on the page is my
label.

In my code behind file i have the following:

protected void Page_Load(object sender, System.EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginTask),
new EndEventHandler(EndTask),
null,
null);

RegisterAsyncTask(task);
Page.ExecuteRegisteredAsyncTasks();
}

public IAsyncResult BeginTask(object sender, EventArgs e,
AsyncCallback cb, object state)
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionSt ring.
["conn"].ConnectionString))
{
cmd = new SqlCommand("sp_AnheiserBusch_GetWeeks", cn);
cmd.CommandType = CommandType.StoredProcedure;
IAsyncResult ar;

try
{
cn.Open();
ar = cmd.BeginExecuteReader(cb, state);
}
finally
{
cn.Close();
}

return ar;
}
}

public void EndTask(IAsyncResult ar)
{
mylabel.Text = "EndTask";
}

Thanks.
Jan 7 '08 #1
3 2531
as you close the connection right after starting the async query, it should
throw an error. you can not close the connection until the results are read
with:

cmd.EndExecuteReader()

which should be called in the end handler.

-- bruce (sqlwork.com)
"mm*********@gmail.com" wrote:
I'm trying to set up a test asynchronously executing page that will
call a database stored procedure and then simply add text to a Label
control name mylabel However after executing the BeginEventHandler,
the EndEventHandler is not called and I have no idea why any help is
appreciated. My .aspx file is minimal the only thing on the page is my
label.

In my code behind file i have the following:

protected void Page_Load(object sender, System.EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginTask),
new EndEventHandler(EndTask),
null,
null);

RegisterAsyncTask(task);
Page.ExecuteRegisteredAsyncTasks();
}

public IAsyncResult BeginTask(object sender, EventArgs e,
AsyncCallback cb, object state)
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionSt ring.
["conn"].ConnectionString))
{
cmd = new SqlCommand("sp_AnheiserBusch_GetWeeks", cn);
cmd.CommandType = CommandType.StoredProcedure;
IAsyncResult ar;

try
{
cn.Open();
ar = cmd.BeginExecuteReader(cb, state);
}
finally
{
cn.Close();
}

return ar;
}
}

public void EndTask(IAsyncResult ar)
{
mylabel.Text = "EndTask";
}

Thanks.
Jan 8 '08 #2
There is no particular advantage in using Async page methods for a single
database call, since page processing is halted until the End method is
complete. If you have multiple calls that you want to have executed in
parallel, then it makes more sense.
The way you have your code now is nothing more than an "exercise".
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"mm*********@gmail.com" wrote:
I'm trying to set up a test asynchronously executing page that will
call a database stored procedure and then simply add text to a Label
control name mylabel However after executing the BeginEventHandler,
the EndEventHandler is not called and I have no idea why any help is
appreciated. My .aspx file is minimal the only thing on the page is my
label.

In my code behind file i have the following:

protected void Page_Load(object sender, System.EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(
new BeginEventHandler(BeginTask),
new EndEventHandler(EndTask),
null,
null);

RegisterAsyncTask(task);
Page.ExecuteRegisteredAsyncTasks();
}

public IAsyncResult BeginTask(object sender, EventArgs e,
AsyncCallback cb, object state)
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionSt ring.
["conn"].ConnectionString))
{
cmd = new SqlCommand("sp_AnheiserBusch_GetWeeks", cn);
cmd.CommandType = CommandType.StoredProcedure;
IAsyncResult ar;

try
{
cn.Open();
ar = cmd.BeginExecuteReader(cb, state);
}
finally
{
cn.Close();
}

return ar;
}
}

public void EndTask(IAsyncResult ar)
{
mylabel.Text = "EndTask";
}

Thanks.
Jan 8 '08 #3
mm*********@gmail.com wrote:
cmd = new SqlCommand("sp_AnheiserBusch_GetWeeks", cn);
it's better not to name stored procedures with sp_
http://msdn2.microsoft.com/en-us/library/ms190669.aspx
Jan 8 '08 #4

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

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
4
by: Jason Chu | last post by:
I have a big asp.net app that does many functions, some do alot of database cross searching, some that does upload/download from database. When two users use the application, sometimes, if one of...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
4
by: Random | last post by:
Has anyone here implemented RegisterAsyncTask and PageAsyncTask to improve page performance on page databinding? The only samples I've been able to find on this involve using asynchronous...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.