6

If I just run one of the async events everything executes exactly as it should be. However, when I add in all 3 of my events, I get (from what I gather) a timeout from my syntax. Here is a full stack-trace that will hopefully assist.


System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object..
at System.Web.UI.Page.d__554.MoveNext()
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.d__554.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
at System.Web.UI.Page.AsyncPageEndProcessRequest(IAsyncResult result)
at ASP.pages_AsyncTest1_aspx.EndProcessRequest(IAsyncResult ar) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\14a1541c\96dbdee3\App_Web_AsyncTest1.aspx.f9b0821e.cqtg2bnc.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Exception type: System.Web.HttpUnhandledException
Message : Exception of type 'System.Web.HttpUnhandledException' was thrown.
Stacktrace:
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.d__554.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar)
at System.Web.UI.Page.AsyncPageEndProcessRequest(IAsyncResult result)
at ASP.pages_AsyncTest1_aspx.EndProcessRequest(IAsyncResult ar) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\14a1541c\96dbdee3\App_Web_AsyncTest1.aspx.f9b0821e.cqtg2bnc.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

And here is the C# syntax I want to execute:

namespace CEDS
{
  public partial class BBLL : System.Web.UI.UserControl
  {
      private DataSet DS = new DataSet();
      private DataSet DS1 = new DataSet();
      private DataSet DS2 = new DataSet();

      protected void Page_Load(object sender, EventArgs e)
      {
        if (!IsPostBack)
        {
            Page.RegisterAsyncTask(new PageAsyncTask(RunSQLUSP)); 
        }
      }
      public async System.Threading.Tasks.Task RunSQLUSP()
      {
          var t1 = GetDataForDropDown1();
          var t2 = GetDataForDropDown2();
          var t3 = GetDataForDropDown3();
          //This line is hit then error is thrown 
          await System.Threading.Tasks.Task.WhenAll(t1, t2, t3);

          //Bind Data to grids/dropdowns

        }
    }
}

async System.Threading.Tasks.Task<DataSet> GetDataForDropDown1()
{   
  DS = GetDataForDropDown1();
  return DS;            
}
async System.Threading.Tasks.Task<DataSet> GetDataForDropDown2()
{   
  DS2 = GetDataForDropDown2();
  return DS2;           
}
async System.Threading.Tasks.Task<DataSet> GetDataForDropDown3()
{   
  DS = GetDataForDropDown3();
  return DS;          
}

1 Answer 1

9

Refer to this answer.

You need to set the AsyncTimeout property on your aspx. The reason for the exception is that your asynchronous operation exceeded the current AsyncTimeout value which I'm guessing is in default. The value should be in milliseconds.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BBLL.aspx.cs" Inherits="Sample03.Default" Async="true" AsyncTimeout="600000" %> //10 mins
Sign up to request clarification or add additional context in comments.

3 Comments

I added in the timeout as suggested but now it throws a NullReference Exception?
Which line throws the exception?
This seems to be a different issue with your code since you have gone past the Timeout exception. Try creating a List<Task> tasks, add t1,t2 and t3 then use tasks as parameter to WhenAll

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.