Skip to content

Commit

Permalink
Don't resume the PortableTimer background task on the captured contex…
Browse files Browse the repository at this point in the history
…t that initiated it.
  • Loading branch information
nblumhardt committed Nov 20, 2015
1 parent 8ae5284 commit e5f3858
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Serilog/Sinks/PeriodicBatching/PortableTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async void Start(TimeSpan interval)

try
{
await Task.Delay(interval, _cancel.Token);
await Task.Delay(interval, _cancel.Token).ConfigureAwait(false);

_state = PortableTimerState.Active;

Expand All @@ -90,8 +90,6 @@ public void Dispose()

while (true)
{
// Thread.Sleep() would be handy here...

lock (_stateLock)
{
if (_state == PortableTimerState.Disposed ||
Expand All @@ -101,6 +99,8 @@ public void Dispose()
return;
}
}

Thread.Sleep(10);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,9 @@ public void WhenAnEventIsEnqueuedItIsWrittenToABatch_OnFlush()
public void WhenAnEventIsEnqueuedItIsWrittenToABatch_OnTimer()
{
var pbs = new InMemoryPeriodicBatchingSink(2, TinyWait, TimeSpan.Zero);
Task.Run(() =>
{
Console.WriteLine("TEST: Writing");
var evt = Some.InformationEvent();
pbs.Emit(evt);
});
Console.WriteLine("TEST: Sleeping");
Thread.Sleep(TimeSpan.FromSeconds(1));
Console.WriteLine("TEST: Stopping");
var evt = Some.InformationEvent();
pbs.Emit(evt);
Thread.Sleep(TinyWait + TinyWait);
pbs.Stop();
Assert.Equal(1, pbs.Batches.Count);
Assert.False(pbs.WasCalledAfterDisposal);
Expand Down

0 comments on commit e5f3858

Please sign in to comment.