Skip to content

Instantly share code, notes, and snippets.

View cilliemalan's full-sized avatar

Cillié Malan cilliemalan

View GitHub Profile
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await DoWorkAsync(stoppingToken);
}
}
}
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using var disposer = messageQueue.Subscribe(async (msg) =>
{
await ProcessMessageAsync(msg, stoppingToken);
});
// Nasty!
@cilliemalan
cilliemalan / asyncawaiter.cs
Created November 18, 2019 12:01
An awaiter for CancellationToken
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Core
{
@cilliemalan
cilliemalan / MainView.cs
Last active July 1, 2020 17:35
A workaround for multisampling in MonoGame under UWP by rendering to texture first.
/*
One cannot use multisampling directly in a UWP application because
of reasons stipulated here:
https://docs.microsoft.com/tr-tr/windows/uwp/gaming/multisampling--multi-sample-anti-aliasing--in-windows-store-apps
The workaround is to create a render target with multisampling, render to that
and then render the render target as a sprite
*/
using System;
using System.Collections.Generic;
' .Net 1.1 and Later
Imports System.Threading
Public NotInheritable Class MessageSequencer
Implements IDisposable
Private _disposed As Integer = 0
ReadOnly _waitThread As Thread
ReadOnly _mre As New ManualResetEvent(False)