Skip to content

Instantly share code, notes, and snippets.

View OlegKarasik's full-sized avatar

Oleg Karasik OlegKarasik

View GitHub Profile
@OlegKarasik
OlegKarasik / Program.cs
Last active January 18, 2024 13:28
Code Tip: How to invoke delegate with arguments from dependency injection container?
// The explanation can be found here: https://wp.me/pa1cW1-2B
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
@OlegKarasik
OlegKarasik / Program.cs
Last active December 5, 2018 13:42
Verify Stateful Service Life Cycle
internal static class Program
{
private static void Main()
{
try
{
ServiceRuntime.RegisterServiceAsync("SlowStatefulServiceType",
context => new SlowStatefulService(context)).GetAwaiter().GetResult();
Thread.Sleep(Timeout.Infinite);
@OlegKarasik
OlegKarasik / Program.cs
Created December 5, 2018 11:40
Verify Stateless Service life-cycle
internal static class Program
{
private static void Main()
{
try
{
ServiceRuntime.RegisterServiceAsync("SlowStatelessServiceType",
context => new SlowStatelessService(context)).GetAwaiter().GetResult();
Thread.Sleep(Timeout.Infinite);
@OlegKarasik
OlegKarasik / Demo.cs
Last active January 30, 2023 14:35
Code Tip: How to work with asynchronous event handlers in C#?
public class Demo
{
public event EventHandler DemoEvent;
public void Raise()
{
this.DemoEvent?.NaiveRaiseAsync(this, EventArgs.Empty).GetAwaiter().GetResult();
Console.WriteLine("All handlers have been executed!");
}
}
@OlegKarasik
OlegKarasik / Program.cs
Created October 28, 2019 11:59
What is wrong with this code? Part 2.
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace Application
{
public sealed class Query
{
public readonly string StringValue;