Skip to content

Commit b6f5d0e

Browse files
committed
Change to Interlocked.Increment
1 parent 59534f5 commit b6f5d0e

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/Moryx/Threading/ParallelOperations.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,8 @@ public int ScheduleExecution<T>(Action<T> operation, T userState, int delayMs, i
128128
/// </summary>
129129
public int ScheduleExecution<T>(Action<T> operation, T userState, int delayMs, int periodMs, bool criticalOperation) where T : class
130130
{
131-
int id;
132-
lock (_runningTimers)
133-
{
134-
id = ++_lastTimerId;
135-
}
131+
// thread safe increment of timer id
132+
int id = Interlocked.Increment(ref _lastTimerId);
136133

137134
var timer = new Timer(new NonStackingTimerCallback(state =>
138135
{

0 commit comments

Comments
 (0)