OrangeCube/MinimumAsyncBridge

Incorrect Timer usage

Closed this issue · 3 comments

NN--- commented

In https://github.com/OrangeCube/MinimumAsyncBridge/blob/master/src/MinimumAsyncBridge/Threading/Tasks/Task.cs#L373

There is code

Timer t = null;
t = new Timer(_ => use of 't')

If the callback runs before the assignment it won't work correctly.
A correction solution is to use Elapsed += .

ufcpp commented

Is it possible? The Delay returns before t = new Timer(callback) if millisecondsDelay is zero. Thus, the callback is always invoked after the t assigned. (Maybe. it might be null on the worst case context switching... I'm not confident.)

Anyway. the Elapsed event is a member of the System.Timers.Timer. The Timer used in the Delay is the System.Threading.Timer which doesn't have it.

NN--- commented

Possible if you put '1' .
You can make a Timer with infinite values and then change dueTime.

var t = new Timer( ..., Timeout.Infinite, Timeout.Infinite);
t.Change(dueTime, Timeout.Infinite)

Not sure if you really need Interlocked.Read here , guess it is not needed.

ufcpp commented

Fixed: #19

The fixed package is published in https://www.nuget.org/packages/MinimumAsyncBridge/0.9.20