Skip to content

Instantly share code, notes, and snippets.

View NtFreX's full-sized avatar
🐢
Work in progress...

NtFreX

🐢
Work in progress...
View GitHub Profile
using SDL2;
using System.Collections;
namespace NtFreX.BuildingBlocks
{
public class SdlAudioRenderer : IDisposable
{
private SDL.SDL_AudioSpec? loadedFormat = null;
private bool isOpen = false;
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();
public struct NonThrowingAwaitable
{
private readonly Task _task;
private readonly bool _continueOnCapturedContext;
public NonThrowingAwaitable(Task task, bool continueOnCapturedContext)
{
_task = task;
_continueOnCapturedContext = continueOnCapturedContext;
}
public class MessagePumpDispatcher : IDisposable
{
private readonly ManualResetEventSlim _creatingThreadComplete;
private readonly CancellationTokenSource _cancellationTokenSource;
private readonly Thread _thread;
private Dispatcher _dispatcher;
public MessagePumpDispatcher()
{
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()
{
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 = "";
/*
public void Configure()
{
services.Configure<CertificateBasedDataProtectorOptions>(x => ...)
services.TryAddSingleton<IDataProtectionProvider, CertificateBasedDataProtectionProvider>();
}
*/
public sealed class CertificateBasedDataProtectionProvider : IDataProtectionProvider
{
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; }
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;
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)
{