Long-running tasks in event handlers

Hi, we are wondering whether it is bad idea to have long-running tasks in event

handlers, like video encoding. Specifically we were thinking about what happens

in the case of heartbeat timeouts / network errors when an event handler is

running. Will the “SubscriptionDropped” event be called (where we resubscribe)?

Is there a chance that the event handler will be called again before the first

one is finished?

In other words, should we make our event handlers resilient to potentially being

invoked multiple times “simultaneously”?

The code is more or less

var conn = ConnectionSettings.Create()
.KeepReconnecting()
.SetReconnectionDelayTo(TimeSpan.FromSeconds(5))
.SetHeartbeatInterval(TimeSpan.FromSeconds(30))
.SetHeartbeatTimeout(TimeSpan.FromSeconds(30));

var connection = EventStoreConnection.Create(conn, new IPEndPoint(…));
connection.ConnectAsync().Wait();

private void Subscribe() {
var subscriptionSettings = …;
sub = connection.SubscribeToStreamFrom(
“stream”,
null,
subscriptionSettings,
GotEventAsync,
subscriptionDropped: Dropped
);
}

private async Task GotEventAsync(EventStoreCatchUpSubscription arg1, ResolvedEvent resolvedEvent)
{
await DoWork();
}

private void Dropped(EventStoreCatchUpSubscription arg1, SubscriptionDropReason dropReason, Exception ex)
{
sub.Stop();
Subscribe();
}

``