Just wondering how I can replace the AutoResetEvent in the below? I was trying to think how to do it the RX way or with tasks, but I can see how to do it.
public void LogOnResponse LogOn()
{
LogOnResponse logOnResponse = null;
var waitEvent = new AutoResetEvent(false);
var listener = _connection.LoginStatusEvent
.Where(x => x.LoginState == LoginState.LoggedOn
|| x.LoginState == LoginState.LoggedRejected);
listener.Subscribe(x => {
logOnResponse = new LogOnResponse();
logOnResponse.InformationMessage = x.Message;
logOnResponse.IsAuthenticated = x.LoginState == LoginState.LoggedOn;
waitEvent.Set();
});
connection.Login(connectionInfo);
waitEvent.WaitOne(2000);
return logOnResponse;
}
Consider structuring the code like so:
We use
Publish
to so that order of execution doesn't matter, and RefCount() to hide theConnectableObservable