.net client api, ConnectAsync behaviour


Should I expect the return value of this to be false after 5 seconds, if no event store is running?



Depends what your connection settings are about retrying and reconnecting


I know this is an old thread, but I am curious about this as well. I would expect calling “ConnectAsync().Wait()” to fail with an exception on the Task if EventStore is not running at the specified endpoint. However, when I call this method with EventStore not running and default connection settings, the Task completes immediately. No connection succeeds, and no exception is reported on the task returned by ConnectAsync(). Is this the expected behavior of the method? If so, how can I check whether or not the connection has succeeded?


Keepretrying is set by default iirc maybe no retrying is a better default


Discussion: https://github.com/EventStore/EventStore/issues/377

Thanks Greg. I guess, from the documentation that I read, it wasn’t clear that KeepReconnecting() was the default, but the other defaults were clearly marked. Also, is there a way, with a limited number of connection reattempts, that IEventStoreConnection signals some some sort of ultimate failure to connect, or do we just have to wait on our own specified timeout?

it depends what you set in settings. You can say reconnect every n
seconds forever. Never reconnect. Reconnect up to 10 times at 5 second
intervals etc etc

Ok, I think I understand. So, through those mechanisms, we are able to indirectly control the maximum amount of time that we would have to wait before we can assume a connection is established.



I guess I mean indirectly in the sense that we aren’t doing something like ConnectAsync(“specify your absolute maximum allowable wait time or other behavior configuration here”). The settings that actually determine how the method behaves are not specified directly in the input to the method itself. If I am specifying the connection settings in one part of my code, say, setting up an instance of IEventStoreConnection to be used via dependency injection, and calling ConnectAsync().Wait(“some timeout”) in another part of my code, I have to make sure that I calculate my timeout correctly based on my connection settings configuration and keep my wait timeout in sync with those settings. That’s not a big deal though, because it is only ever called once.

A slight correction. Because ConnectAsync().Wait() returns immediately, I’m having to do something more like this.

private readonly IEventStoreConnection connection;
private readonly EventStoreEventDispatcher dispatcher;
private readonly ManualResetEventSlim exitEvent = new ManualResetEventSlim(false);
private readonly ManualResetEventSlim connectedEvent = new ManualResetEventSlim(false);

public void Run() {
Log.Info(“Connecting to EventStore”);
this.connection.Connected += this.EventStoreConnected;
if (this.connected) {
else {
Log.Error(“Failed to connect to EventStore”);

public void EventStoreConnected(object sender, ClientConnectionEventArgs args) {
Log.Info(“Connected to EventStore”);
if (!this.connected) {
this.connected = true;