This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SDL2; | |
using System.Collections; | |
namespace NtFreX.BuildingBlocks | |
{ | |
public class SdlAudioRenderer : IDisposable | |
{ | |
private SDL.SDL_AudioSpec? loadedFormat = null; | |
private bool isOpen = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MessagePumpProxy<T> : RealProxy | |
{ | |
private readonly T _instance; | |
private readonly MessagePumpDispatcher _messagePumpDispatcher; | |
private MessagePumpProxy(T instance) | |
: base(typeof(T)) | |
{ | |
_instance = instance; | |
_messagePumpDispatcher = new MessagePumpDispatcher(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct NonThrowingAwaitable | |
{ | |
private readonly Task _task; | |
private readonly bool _continueOnCapturedContext; | |
public NonThrowingAwaitable(Task task, bool continueOnCapturedContext) | |
{ | |
_task = task; | |
_continueOnCapturedContext = continueOnCapturedContext; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MessagePumpDispatcher : IDisposable | |
{ | |
private readonly ManualResetEventSlim _creatingThreadComplete; | |
private readonly CancellationTokenSource _cancellationTokenSource; | |
private readonly Thread _thread; | |
private Dispatcher _dispatcher; | |
public MessagePumpDispatcher() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SingleStaTaskScheduler : TaskScheduler, IDisposable | |
{ | |
private readonly BlockingCollection<Task> _taskQueue = new BlockingCollection<Task>(); | |
private readonly CancellationTokenSource _cancellationTokenSource; | |
private readonly object _lock = new object(); | |
private readonly EventWaitHandle _eventWaitHandle; | |
private readonly Thread _staThread; | |
public SingleStaTaskScheduler() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class DevExpressConverter | |
{ | |
public static string ConvertRtfToHtml(string rtf) | |
{ | |
var ms = new MemoryStream(); | |
var writer = new StreamWriter(ms); | |
writer.Write(rtf); | |
writer.Flush(); | |
ms.Position = 0; | |
var output = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
public void Configure() | |
{ | |
services.Configure<CertificateBasedDataProtectorOptions>(x => ...) | |
services.TryAddSingleton<IDataProtectionProvider, CertificateBasedDataProtectionProvider>(); | |
} | |
*/ | |
public sealed class CertificateBasedDataProtectionProvider : IDataProtectionProvider | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class RateLimitedFunctionBase<T> | |
{ | |
private readonly Func<object[], Task<T>> _func; | |
private readonly Func<object[], Task<bool>> _doNotRateLimitWhen; | |
private readonly SemaphoreSlim _semaphoreSlim; | |
private DateTime _lastExecution; | |
public TimeSpan MaxAllowedInterval { get; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TaskQueue | |
{ | |
public bool IsRunning => _longRunningTasks.Count > 0 || _semaphoreSlim.CurrentCount != _maxConcurentActions; | |
public event EventHandler<bool> IsRunningChanged; | |
private bool _oldIsRunningValue; | |
private readonly int _maxConcurentActions; | |
private readonly Queue<LongRunningTask> _longRunningTasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class CachedFunctionBase<T> | |
{ | |
private readonly Func<object[], Task<T>> _func; | |
private readonly SemaphoreSlim _semaphoreSlim; | |
private readonly List<(DateTime DateTime, object[] Arguments, T Result)> _lastResults; | |
public TimeSpan CachingTime { get; } | |
protected CachedFunctionBase(Func<object[], Task<T>> func, TimeSpan minAllowedInterval) | |
{ |