2012-09-12 3 views
0

비동기 작업을 사용하지만 반환하는 IAsyncResult.AsyncState가 항상 null 인 다음 프로그램이 있습니다.왜 내 asyncResult가 항상 null입니까?

내가 뭘 잘못하고있어?

public interface ICommandService 
{ 
[OperationContract(AsyncPattern = true)] 
IAsyncResult BeginLogin(string userName, string password, AsyncCallback callback, object state); 

string EndLogin(IAsyncResult result); 
} 

class CommandService : ICommandService 
{ 
    public string Login(string userName, string password) 
    {    
     return "dorcohen"; 
    } 

    private Func<string, string, string> _LoginDelgateObject; 

    public IAsyncResult BeginLogin(string userName, string password, AsyncCallback callback, object state) 
    { 
     Func<string, string, string> function = new Func<string, string, string>(Login); 
     _LoginDelgateObject = function; 
     IAsyncResult result = function.BeginInvoke(userName, password, callback, state); 
     return result; 
    } 

    public string EndLogin(IAsyncResult result) 
    { 
     CommandService test = result.AsyncState as CommandService; 
     return test._LoginDelgateObject.EndInvoke(result); 
    } 
} 
+0

에 다음 코드를 사용하지 못할. 전화 코드를 보여 주시겠습니까? –

+0

@EfranCobisi 감사합니다. 실제로 국가와 관련이 있습니다. –

답변

1

당신은 그것이 _state_가 다른 매개 변수와 함께 전달되는대로 BeginLogin()를 호출하는 방식에 따라 달라 보인다 BeginLogin 방법

function.BeginInvoke(userName, password, callback, this); 
관련 문제