mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
35 lines
814 B
C#
35 lines
814 B
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Threading;
|
|
|
|
namespace BTCPayServer
|
|
{
|
|
public struct SynchronizationContextRemover : INotifyCompletion
|
|
{
|
|
public bool IsCompleted => SynchronizationContext.Current == null;
|
|
|
|
public void OnCompleted(Action continuation)
|
|
{
|
|
var prev = SynchronizationContext.Current;
|
|
try
|
|
{
|
|
SynchronizationContext.SetSynchronizationContext(null);
|
|
continuation();
|
|
}
|
|
finally
|
|
{
|
|
SynchronizationContext.SetSynchronizationContext(prev);
|
|
}
|
|
}
|
|
|
|
public SynchronizationContextRemover GetAwaiter()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
public void GetResult()
|
|
{
|
|
}
|
|
}
|
|
}
|