Skip to content

Commit

Permalink
Apply luk suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 committed Mar 6, 2024
1 parent 101108f commit 62a3866
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,19 @@ private void UpdateSyncModes(SyncMode newModes, string? reason = null)
// for example when switching to Full sync we need to ensure that we safely transition
// DBS and processors if needed

Preparing?.Invoke(this, args);
Changing?.Invoke(this, args);
ParallelInvoke(Preparing, args);
ParallelInvoke(Changing, args);
Current = newModes;
if (Changed is not null)
ParallelInvoke(Changed, args);

void ParallelInvoke(EventHandler<SyncModeChangedEventArgs> handler, SyncModeChangedEventArgs args)
{
Parallel.ForEach(Changed.GetInvocationList(),
deleg => deleg.DynamicInvoke(this, args));
EventHandler<SyncModeChangedEventArgs> handlerCopy = handler;
if (handlerCopy is not null)
{
Parallel.ForEach(handlerCopy.GetInvocationList(),
deleg => deleg.DynamicInvoke(this, args));
}
}
}

Expand Down

0 comments on commit 62a3866

Please sign in to comment.