클라이언트 쪽에서 비동기 PageMethod
호출을 호출하고 있습니다. 백엔드 코드는BeginInvoke 메서드 및 세션 상태
[WebMethod(EnableSession = true)]
public static string BeginMethodCall()
{ //Session Accessible here
string g = Guid.NewGuid().ToString();
Func<object> f =() => MethodCall();
IAsyncResult asyncCall = f.BeginInvoke(null, f);
lock (AsyncThreadPool)
AsyncThreadPool[g] = asyncCall;
return g;
}
[WebMethod(EnableSession=true)]
public static object EndMethodCall(string guId)
{
IAsyncResult callResult;
lock (AsyncThreadPool)
{
callResult = AsyncThreadPool[guId];
AsyncThreadPool.Remove(guId);
}
Func<object> f = (Func<object>)callResult.AsyncState;
callResult.AsyncWaitHandle.WaitOne();
return f.EndInvoke(callResult);
}
[WebMethod(EnableSession = true)]
public static object MethodCall()
{
//Session not accessible here
}
세션 상태가 BeginMethodCall()
및 EndMethodCall()
에서가 아니라 MethodCall()
에서 액세스 할 수 있습니다.
아무도 왜 내 세션 상태가 없어지는지 알 수 있습니까?
- asyn 호출이 스레드로부터 안전하지 않기 때문에 스레드가 세션 컨텍스트를 잃어 버릴 수 있습니까?
- 여기서 세션에 액세스 할 수있는 방법이 있습니까?