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 System; | |
using System.Collections; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.ComponentModel; | |
using System.Collections.Generic; | |
namespace ConsoleApplication | |
{ | |
public class Program |
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 System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
namespace ProductsApp.Controllers | |
{ |
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 System; | |
using System.Runtime.InteropServices; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication | |
{ | |
// by noseratio - stackoverflow.com/users/1768303/noseratio | |
class TaskExt | |
{ |
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
// http://stackoverflow.com/q/31495411/1768303 | |
// use: await Task.Delay(5000, token.CreateAsynCancellationToken()); | |
public static CancellationToken CreateAsynCancellationToken(this CancellationToken @this) | |
{ | |
var cts = new CancellationTokenSource(); | |
var reg = default(CancellationTokenRegistration); | |
reg = @this.Register(() => | |
{ | |
ThreadPool.QueueUserWorkItem(_ => |
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
// http://stackoverflow.com/q/31522642/1768303 | |
using System; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Security; | |
using System.Security.Principal; | |
using System.Threading; | |
using System.Threading.Tasks; |
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
// http://stackoverflow.com/questions/32412426/unexpected-stack-overflow-despite-yielding | |
public static class TaskExt | |
{ | |
public static AlwaysAsyncAwaiter<T> AlwaysAsync<T>(this Task<T> @this) { return new AlwaysAsyncAwaiter<T>(@this); } | |
public struct AlwaysAsyncAwaiter<T> : System.Runtime.CompilerServices.ICriticalNotifyCompletion | |
{ | |
readonly Task<T> _task; |
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 System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace UnobservedTaskExceptionDemo | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
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
<# | |
This is a workaround for "node-gyp is unable to find msbuild if VS2019 is installed" | |
https://github.com/nodejs/node-gyp/issues/1663 | |
It create a shim EXE as "MSBuild\15.0\Bin\MSBuild.exe" to target "MSBuild\Current\Bin\MSBuild.exe" | |
By noseratio - MIT license - use at your own risk! | |
It requires admin mode, I use wsudo/wsudox (https://chocolatey.org/packages/wsudo) for that: | |
wsudo powershell -f make-msbuild-shim.ps1 | |
#> | |
#Requires -RunAsAdministrator |
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 Diags | |
{ | |
public static void Log( | |
string message, | |
[System.Runtime.CompilerServices.CallerMemberName] string callerName = "", | |
[System.Runtime.CompilerServices.CallerLineNumber] int lineNumber = 0, | |
[System.Runtime.CompilerServices.CallerFilePath] string filePath = "") | |
{ | |
// trim trailing new line characters | |
var trimmedMessage = message.TrimEnd(Environment.NewLine.ToCharArray()); |
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
/// <summary> | |
/// Wrap an event as Task | |
/// </summary> | |
/// <see href="https://stackoverflow.com/a/22798789/1768303"/> | |
public static async Task<TEventArgs> FromEvent<TEventHandler, TEventArgs>( | |
Func<Action<TEventArgs>, Action, Action<Exception>, TEventHandler> getHandler, | |
Action<TEventHandler> subscribe, | |
Action<TEventHandler> unsubscribe, | |
Action<Action<TEventArgs>, Action, Action<Exception>> initiate, | |
CancellationToken token = default) where TEventHandler : Delegate |
OlderNewer