Skip to content

Commit 1f21b41

Browse files
committed
move try/catch down
1 parent 238e766 commit 1f21b41

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/WorkflowCore/Services/LifeCycleEventPublisher.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LifeCycleEventPublisher : ILifeCycleEventPublisher, IDisposable
1414
private readonly ILifeCycleEventHub _eventHub;
1515
private readonly ILogger _logger;
1616
private readonly BlockingCollection<LifeCycleEvent> _outbox;
17-
protected Task DispatchTask;
17+
private Task _dispatchTask;
1818

1919
public LifeCycleEventPublisher(ILifeCycleEventHub eventHub, ILoggerFactory loggerFactory)
2020
{
@@ -33,21 +33,20 @@ public void PublishNotification(LifeCycleEvent evt)
3333

3434
public void Start()
3535
{
36-
if (DispatchTask != null)
36+
if (_dispatchTask != null)
3737
{
3838
throw new InvalidOperationException();
3939
}
4040

41-
DispatchTask = new Task(Execute);
42-
DispatchTask.Start();
41+
_dispatchTask = new Task(Execute);
42+
_dispatchTask.Start();
4343
}
4444

4545
public void Stop()
4646
{
4747
_outbox.CompleteAdding();
48-
49-
DispatchTask.Wait();
50-
DispatchTask = null;
48+
_dispatchTask.Wait();
49+
_dispatchTask = null;
5150
}
5251

5352
public void Dispose()
@@ -57,16 +56,16 @@ public void Dispose()
5756

5857
private async void Execute()
5958
{
60-
try
59+
foreach (var evt in _outbox.GetConsumingEnumerable())
6160
{
62-
foreach (var evt in _outbox.GetConsumingEnumerable())
61+
try
6362
{
6463
await _eventHub.PublishNotification(evt);
6564
}
66-
}
67-
catch (Exception ex)
68-
{
69-
_logger.LogError(default(EventId), ex, ex.Message);
65+
catch (Exception ex)
66+
{
67+
_logger.LogError(default(EventId), ex, ex.Message);
68+
}
7069
}
7170
}
7271
}

0 commit comments

Comments
 (0)