I have an interesting problem.. I have a login method which works a WCF service.
I created a taskcompletion and waits until result is come.
Well problem is, if I call 2 times login method, the second one does not return anything. I put break point and it enters the completed event and it calls trysetresult but nothing return.
here is my code
public Task<User> LoginByUserName(string userName, string password)
{
var tcs = new TaskCompletionSource<User>();
if (!_registeredEventList.Contains ("LoginByUserNameCompleted")) {
_registeredEventList.Add ("LoginByUserNameCompleted");
userService.LoginByUserNameCompleted += (object sender, LoginByUserNameCompletedEventArgs args) => {
if (args.Error != null)
tcs.TrySetException (args.Error);
if (args.Result != null)
tcs.TrySetResult (args.Result);
else
tcs.TrySetResult (null);
};
}
userService.LoginByUserNameAsync (userName,password);
return tcs.Task;
}
I call like that;
var loginResult= await Task.Run(()=>serviceHelper.LoginByUserName(userName,password));
For example, if user one time entered wrong login info, in the second try, nothing will return.
PS: _registeredEventList holds if event is already subscribed or not. If yes then it does not creat again. When I delete that part, it works.