RestSharp 구현시 다음과 같은 문제가 있습니다. 계속하기 전에 내 신청서가 ExecuteAsync()
의 응답을 기다리게하려면 어떻게해야합니까?ExecuteAsync() 결과 기다림
내가 노력 다른 솔루션 :
먼저 (이 방법은 ExecuteAsync 응답을 기다리지 않습니다는) :
public Task<Connection> Connect(string userId, string password)
{
var client = new RestClient(_baseUrl)
{
Authenticator = new SimpleAuthenticator("user", userId,
"password", password)
};
var tcs = new TaskCompletionSource<Connection>();
var request = new RestRequest(AppResources.Authenticating);
client.ExecuteAsync<Connection>(request, response =>
{
tcs.SetResult(new JsonDeserializer().
Deserialize<Connection>(response));
});
return tcs.Task;
}
그래서 나는이 시도하지만, 응용 프로그램이 정지 :
public Task<Connection> Connect(string userId, string password)
{
EventWaitHandle executedCallBack = new AutoResetEvent(false);
var client = new RestClient(_baseUrl)
{
Authenticator = new SimpleAuthenticator("user", userId,
"password", password)
};
var tcs = new TaskCompletionSource<Connection>();
var request = new RestRequest(AppResources.Authenticating);
client.ExecuteAsync<Connection>(request, response =>
{
tcs.SetResult(new JsonDeserializer().
Deserialize<Connection>(response));
executedCallBack.Set();
});
executedCallBack.WaitOne();
return tcs.Task;
}
무엇이'RestClient'입니까? – Default
'RestSharp' 라이브러리,'WebClient'의 일종입니다. – user2169047
what 's Connection? RestSharp에서이 클래스를 찾을 수 없습니다. – adrian4aes