Skip to content

Instantly share code, notes, and snippets.

View NeverMorewd's full-sized avatar
🍋
Looking forward to next meeting

nevermore NeverMorewd

🍋
Looking forward to next meeting
View GitHub Profile
@walterlv
walterlv / AwaiterInterfaces.cs
Created July 11, 2018 12:55
Custom awaiter with background UI thread
using System.Runtime.CompilerServices;
namespace Walterlv.Threading
{
/// <summary>
/// 表示一个可等待对象,如果一个方法返回此类型的实例,则此方法可以使用 `await` 异步等待。
/// </summary>
/// <typeparam name="TAwaiter">用于给 await 确定返回时机的 IAwaiter 的实例。</typeparam>
public interface IAwaitable<out TAwaiter> where TAwaiter : IAwaiter
{
@nblumhardt
nblumhardt / Program.cs
Last active September 4, 2024 10:05
Enrich.WithCaller()
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
namespace ConsoleApp24
@bartoszkp
bartoszkp / EnumGetValuesTest.cs
Last active August 18, 2022 13:16
Enum.GetValues: cast vs. no cast to typed array test.
// Intel(R) Core(TM) i7-2600 CPU @ 3.40 GHz 3.40 GHz
// 16 GB RAM, Windows 7, 64 bit
//
//No cast:0.854751600000001 +- 0.182965645566156ms
//Cast:0.724137 +- 0.148216330378943ms
// Conclusion: Cast is indeed faster, but remember that we are talking here about _miliseconds_
// for 1000 enumerations of an enum with 1000 elements. First verify whether this is really significant in your code, before
// proceeding with micro-optimizations.
// Context: http://stackoverflow.com/a/105402/2642204