gpt4 book ai didi

c# - 使用异步时超时

转载 作者:太空狗 更新时间:2023-10-29 23:06:03 24 4
gpt4 key购买 nike

如果我只运行一个异步事件,一切都会按预期执行。但是,当我添加所有 3 个事件时,(从我收集到的)我的语法超时。这是一个完整的堆栈跟踪,希望能提供帮助。


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)

这是我要执行的 C# 语法:

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;
}

最佳答案

引用这个answer .

您需要在您的 aspx 上设置 AsyncTimeout 属性。异常的原因是您的异步​​操作超过了我猜默认的当前 AsyncTimeout 值。该值应以毫秒为单位。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BBLL.aspx.cs" Inherits="Sample03.Default" Async="true" AsyncTimeout="600000" %> //10 mins

关于c# - 使用异步时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35907214/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com