Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:10:53+00:00 2026-05-27T04:10:53+00:00

I have one web page MyWebPage.aspx which while loading has to show data from

  • 0

I have one web page MyWebPage.aspx which while loading has to show data from two webservices along with it’s own algorithm.

1) WebServiceI.SomeMethod() -> Takes 10 seconds aprx. to respond.
2) WebServiceII.SomeMethod() -> Takes 10 seconds aprx. to respond.
3) My Algorithm -> Takes 5 second aprx to respond.

Now,when I call this synchronously,this will take 10+10+5 = 25 seconds to load.

So,I was suggested “Asynchronous Calling Method”,i.e. using IAsyncResult/AsyncCallback.
Now what will(should) happen is that all will be called simultaneously and the page will load in max 10 seconds.

So I call them now in the “Begin/End” way…

public partial class MyWebPage : System.Web.UI.Page
{
    WebServiceI WebServiceIObject = new WebServiceI();
    WebServiceII WebServiceIIObject = new WebServiceII();

protected void Page_Load(object sender, EventArgs e)
{
    //BeginSomeMethod(AsyncCallback callback, object asyncState)[<- Method Signature]
    WebServiceIObject.BeginSomeMethod(OnEndGetWebServiceISomeMethodResult, null);


    //BeginSomeMethod(AsyncCallback callback, object asyncState)[<- Method Signature]
    WebServiceIIObject.BeginSomeMethod(OnEndGetWebServiceIISomeMethodResult, null);


/* My Algorithm 5 seconds*/
DataSet DS = GetDataSetFromSomeWhere();
MyGataGrid.DataSource = DS.tables[0];
MyGataGrid.DataBind();
/* My Algorithm 5 seconds*/


//System.Threading.Thread.Sleep(6000);
}

//Will be called after 10 seconds
void OnEndGetWebServiceISomeMethodResult(IAsyncResult asyncResult)
{
string WebServiceISomeMethodResult = WebServiceIObject.EndSomeMethod(asyncResult);
MyLabelI.Text = WebServiceISomeMethodResult;
//EventLog MyLog = new EventLog("Application"); MyLog.Source = "MySourceI";
//MyLog.WriteEntry(DateTime.Now.ToString());
}

//Will be called after 10 seconds
void OnEndGetWebServiceIISomeMethodResult(IAsyncResult asyncResult)
{
string WebServiceIISomeMethodResult = WebServiceIIObject.EndSomeMethod(asyncResult);
MyLabelII.Text = WebServiceIISomeMethodResult;
//EventLog MyLog = new EventLog("Application"); MyLog.Source = "MySourceII";
//MyLog.WriteEntry(DateTime.Now.ToString());
}
}

Now the issue with the above example is that MyLabelI & MyLabelII Text are never set because the page loads after 5 seconds

and thread is released.Both End Methods are called correctly as checked by writing to EventLog.
How can I resolve this…
something like “All start at once and then all wait till all are complete…”
I understand that if my executing thread waits for 5 seconds more then the code executes as required..

How should I use AsyncWaitHandle…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:10:53+00:00Added an answer on May 27, 2026 at 4:10 am

    Well,The answer to this problem is “System.Web.UI.PageAsyncTask” class.It allows Asynchronous calls to tasks and waits for

    completion on the same thread.Also multiple tasks can be created and made to run parallel.Please go through the documentation

    for further information…Will work in Asp.Net 2.0 & Above Only.

    For our problem above…I am putting “My Algorithm” as sync and both other tasks as Async parallel.So my page will take 10+5

    = 15 seconds to load.

    public partial class MyWebPage : System.Web.UI.Page
    {
    WebServiceI WebServiceIObject = new WebServiceI();
    WebServiceII WebServiceIIObject = new WebServiceII();
    
    protected void Page_Load(object sender, EventArgs e)
    {
    PageAsyncTask PAT_I = new PageAsyncTask
    (BeginGetWebServiceISomeMethodResult, OnEndGetWebServiceISomeMethodResult, null, null, true);
    Page.RegisterAsyncTask(PAT_I);
    
    PageAsyncTask PAT_II = new PageAsyncTask
    (BeginGetWebServiceIISomeMethodResult, OnEndGetWebServiceIISomeMethodResult, null, null, true);
    Page.RegisterAsyncTask(PAT_II);
    
    Page.ExecuteRegisteredAsyncTasks();
    
    /* My Algorithm 5 seconds*/
    DataSet DS = GetDataSetFromSomeWhere();
    MyGataGrid.DataSource = DS.tables[0];
    MyGataGrid.DataBind();
    /* My Algorithm 5 seconds*/
    }
    
    IAsyncResult BeginGetWebServiceISomeMethodResult
        (object Sender, EventArgs EventArgsObject, 
        AsyncCallback AsyncCallbackObject, object PassAnythingExtraIfRequired)
    {
        return WebServiceIObject.BeginSomeMethod(AsyncCallbackObject, PassAnythingExtraIfRequired);
    }
    
     IAsyncResult BeginGetWebServiceIISomeMethodResult
        (object Sender, EventArgs EventArgsObject, 
        AsyncCallback AsyncCallbackObject, object PassAnythingExtraIfRequired)
    {
        return WebServiceIIObject.BeginSomeMethod(AsyncCallbackObject, PassAnythingExtraIfRequired);
    }
    
    void OnEndGetWebServiceISomeMethodResult(IAsyncResult asyncResult)
    {
    string WebServiceISomeMethodResult = WebServiceIObject.EndSomeMethod(asyncResult);
    MyLabelI.Text = WebServiceISomeMethodResult;
    }
    
    void OnEndGetWebServiceIISomeMethodResult(IAsyncResult asyncResult)
    {
    string WebServiceIISomeMethodResult = WebServiceIIObject.EndSomeMethod(asyncResult);
    MyLabelII.Text = WebServiceIISomeMethodResult;
    }
    }
    

    Works 🙂 The code can be made generic with common refactoring…

    Please be careful while planning for this kind of design though…Internally this must also be using threads from threadpool

    only…I have not dug in deep..but must be..So if the tasks happen to take moretime than planned and if several such tasks

    get raised at the same time,then web server could suffer and users could get time out…

    I am still carrying this forward inspite of above flaw as my users will time out anyway if 25 seconds turns out to be 55

    seconds…Better to have a situation where some users are able to work rather than none..

    If there is some better alternative,please post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one page web application, which means alot of javascript. External scripts
I have two data sources: a legacy one (web service) and a database one.
I have a web page with 3 forms on it. Not nested, just one
Here's the situation I have a webpage which has one drop down called prefer.
We have one web application (sharepoint) that collects information from disparate sources. We would
I have one asp.net web application. It is using two membership provider. Two sign-in
I have a asp:DataGrid which holds data in two columns on my webpage. The
I have one button and one gridview in my asp.net web page.I give the
I have two tables that I'm querying from. In one table, there are fields
I have a one page web app so there is no page refreshing. Sometimes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.