Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout when using Async

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;          
}
like image 442
Michael Mormon Avatar asked Mar 10 '16 03:03

Michael Mormon


People also ask

Is setTimeout in async function?

setTimeout — new way: With the help of Node. js development team, we are now able to use async/await syntax while dealing with setTimeout() functions. This feature was initially implemented in Node v. 15, but since version 16 it's in stable status and ready to go.

How do you make asynchronous setTimeout?

export const asyncTimeout = (ms: number) => { return new Promise((resolve) => { setTimeout(resolve, ms); }); }; A simple function, that simply takes in the amount of milliseconds you wish to wait as a parameter. We then immediately return a new Promise, which is resolved when setTimeout completes.

Does async await stop execution?

The await expression causes async function execution to pause until a Promise is settled (that is, fulfilled or rejected), and to resume execution of the async function after fulfillment.

Does async need Athen or await?

We recommend using async/await where possible, and minimize promise chaining. Async/await makes JavaScript code more accessible to developers that aren't as familiar with JavaScript, and much easier to read.

How to reschedule the deadline time in async/await?

The scheduled deadline time is available as .deadline property: Not finished yet timeout can be rescheduled by shift_by () or shift_to () methods: Rescheduling is forbidden if the timeout is expired or after exit from async with code block.

What is the difference between asyncio timeout () and asyncio wait_for ()?

Also it’s much faster than asyncio.wait_for () because timeout doesn’t create a new task. The timeout (delay, *, loop=None) call returns a context manager that cancels a block on timeout expiring:

How to create a timeout in JavaScript?

In order to create the timeout, we will use an asynchronous function that takes in a Promise, as well as a time limit. Since JavaScript’s native setTimeout function uses milliseconds as a parameter, we will use the same to keep things simple. We now need to create a timeoutPromise to use the timeLimit value as a maximum amount of time to run.

Why can't I use await with setTimeout?

await only works on promises. You need to wrap setTimeout in a promise: setTimeout does not return a promise so cannot be await ed. You could create your own promise-based setTimeout and use that.


Video Answer


1 Answers

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
like image 102
John Ephraim Tugado Avatar answered Oct 31 '22 03:10

John Ephraim Tugado