비동기 메서드를 Global.asax의 Session_Start
에서 호출하려면 어떻게해야합니까?Session_Start의 비동기 호출 메서드
Global.asax에 :
protected async Task Session_Start(object sender, EventArgs e)
{
Session.Timeout = 10;
// Do some asynch work
await repository.SetStatsInfo(System.DateTime.Now);
}
비동기 방식 :
나는 기적으로 모두를 실행할 수 있습니다public async Task SetStatsInfo(DateTime time)
{
using (ApplicationDBContext db = new ApplicationDBContext())
{
// Do stuff (update visitors counter in db) ..
await db.SaveChangesAsync();
}
}
(void Session_Start
등을 정의하는) 노력하고 있습니다 만, 타격 있도록 비동기 방식을 선호하는 DB가 차단되지 않습니다.
Session_Start
에 'async Task'와 같이 실행하면 session_start
내의 중단 점이 실행되지 않습니다.
Chris가 올바르게 말했습니다. 단순히 비합리적으로 비동기가되는 이유는 없습니다. http://stackoverflow.com/a/38956850/2410379 –
@DavidPine 그러나 '비동기 작업'호출로만 사용할 수있는 API를 사용해야하는 경우 어떻게해야합니까? Stephen은 분명히 우리에게'GetAwaiter()'나'.Result'를 교착 상태의 위험 때문에 절대로 호출해서는 안된다는 것을 분명히했습니다. ASP는 어떻게 할 수 있습니까?NET 응용 프로그램의'Global''Application_Start' 메쏘드는 안전하게 async 메쏘드를 호출합니까? –
Dai