4
클래스에서 비동기 메서드를 호출하는 웹 페이지 (aspx)가 있습니다. 비동기 메서드는 다음과 같습니다.최종 기다리기 전에 비동기 메소드에서 복귀해도 괜찮습니까?
public async Task<MyThing> GetMyThing()
{
MyThing thing = new MyThing();
var stuff = await Repository.GetStuff();
// apply stuff to thing.
var morestuff = await Repository.GetMoreStuff();
// apply more stuff to thing.
if (someCondition)
{
return thing;
}
var yetMoreStuff = await Repository.GetYetMoreStuff();
// apply yet more stuff
return thing;
}
조건이 충족되면 마지막 저장소 호출의 데이터가 필요하지 않습니다. 마지막 문제가 나에게 문제를 야기하기 전에 돌아 오는 것입니까?
내가 서버 응용 프로그램 로그에이 오류를 받고 있어요, 나는 원인을 사냥하고있어 물어 이유 ...
Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback, System.Object)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback, System.Object)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(System.Threading.ContextCallback, System.Object, System.Threading.Tasks.Task ByRef)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
'돌아 오는'경우 '대기'는 전혀 발생하지 않습니다. – SLaks
코드를 단계별로 실행해야합니다. 그것은 NRE 문제입니다. – Nkosi
오류는 스레딩 때문에 발생하는 것이 아니지만 리포지토리 내의 예외가 발생하고 있습니다. – Chad