Skip to content

Instantly share code, notes, and snippets.

View rahulsahay19's full-sized avatar
💭
Microservices, Azure, Containers, Kubernetes, Infrastructure, Polyglot, etc

rahul sahay rahulsahay19

💭
Microservices, Azure, Containers, Kubernetes, Infrastructure, Polyglot, etc
View GitHub Profile
@rahulsahay19
rahulsahay19 / WhenAllExample.cs
Created November 6, 2023 18:38
WhenAllExample
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
public class WhenAllExample
{
public static async Task Main(string[] args)
{
List<Task<string>> downloadTasks = new List<Task<string>>
@rahulsahay19
rahulsahay19 / AsyncAwaitWithTPLExample.cs
Created November 6, 2023 16:30
AsyncAwaitWithTPLExample
using System;
using System.Threading.Tasks;
public class AsyncAwaitWithTPLExample
{
public static async Task Main(string[] args)
{
Console.WriteLine("Main thread ID: " + Environment.CurrentManagedThreadId);
// Using async/await with TPL
@rahulsahay19
rahulsahay19 / ParallelForEachExample.cs
Created November 6, 2023 16:16
ParallelForEachExample
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class ParallelForEachExample
{
public static void Main(string[] args)
{
List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double sumSquares = 0.0;
@rahulsahay19
rahulsahay19 / ParallelForExample.cs
Created November 6, 2023 16:14
ParallelForExample
using System;
using System.Threading.Tasks;
public class ParallelForExample
{
public static void Main(string[] args)
{
int sum = 0;
Parallel.For(1, 101, i =>
@rahulsahay19
rahulsahay19 / TaskContinuationExample.cs
Last active November 6, 2023 16:07
TaskContinuationExample
using System;
using System.Threading.Tasks;
public class TaskContinuationExample
{
public static void Main(string[] args)
{
Task<int> originalTask = Task.Run(() =>
{
// Simulate some time-consuming computation
@rahulsahay19
rahulsahay19 / hello.cs
Created November 6, 2023 09:10
hello tpl
using System;
using System.Threading.Tasks;
public class TPLBeginnerExample
{
public static void Main(string[] args)
{
// Create and run a task
Task task = Task.Run(() =>
{
public class Singleton
{
private static Singleton instance;
private Singleton() { }
public static Singleton Instance
{
get
{
@rahulsahay19
rahulsahay19 / program.cs
Last active April 17, 2021 19:12
program
internal class Program
{
public static async Task Main(string[] args)
{
LinkedInProfile linkedInProfile = new LinkedInProfile();
try
{
await linkedInProfile.GetProfileWithoutAsync();
}
catch (Exception e)
@rahulsahay19
rahulsahay19 / LinkedInProfile.cs
Last active April 17, 2021 18:47
LinkedInProfile
public class LinkedInProfile
{
private readonly HttpClient _httpClient = new HttpClient();
private readonly string _linkedInProfile = "https://www.linkedin.com/in/rahulsahay19/";
public async Task<string> GetProfileUsingAsync()
{
return await _httpClient.GetStringAsync(_linkedInProfile);
}
@rahulsahay19
rahulsahay19 / Policies.cs
Last active January 11, 2021 15:02
Policies.cs
private static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(5,
retryAttempt => TimeSpan.FromMilliseconds(Math.Pow(2, retryAttempt) * 1000),
(_, waitingTime) =>
{
Console.WriteLine("Retrying.....");
});
}