C# Task问题,错误异常已贴出
小宁_z 2017-09-13 10:59:27 错误提示如:
发生了未经处理的异常,已终止进程。 Application ID: /LM/W3SVC/1/ROOT Process ID: 4040 Exception: System.NullReferenceException Message: 未将对象引用设置到对象的实例。 StackTrace: 在 System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext) 在 System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) 在 System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) 在 System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) 在 System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask) --- End of stack trace from previous location where exception was thrown --- 在 System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(Object s) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch()
应用程序: w3wp.exe Framework 版本: v4.0.30319 说明: 由于未经处理的异常,进程终止。异常信息: System.NullReferenceException 堆栈: 在 System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(System.Object) 在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch()
如上。这是我把网站部署在IIS 后,频繁报的错误(服务器应用程序事件查看看到的)
我觉是我代码用的TASK的问题。
我是这么用的:
private async Task Update(List<TheistEntity> list)
{
await Task.Factory.StartNew(() => {
//do something
)};
}
调用: Update(list).ConfigureAwait(false);
各位大佬看看什么问题,这个错误导致IIS的应用程序池老是自动停了. ASP.NET MVC4