1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
using System.Runtime.InteropServices;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/throwinvalidoperation", () =>
{
throw new System.InvalidOperationException();
});
app.MapGet("/fullgc", () =>
{
System.GC.Collect();
});
app.MapGet("/memincrease", () =>
{
// Gen2
var myList = new List<byte[]>();
for(int i = 0; i < 1000; i++)
{
myList.Add(new byte[10000]);
}
// Promote to Gen2
GC.Collect();
GC.Collect();
GC.Collect();
// LOH
var myLOHList = new List<byte[]>();
myLOHList.Add(new byte[15000000]);
System.GC.Collect();
myLOHList.Add(new byte[15000000]);
System.GC.Collect();
myLOHList.Add(new byte[15000000]);
System.GC.Collect();
// POH
var p1 = GC.AllocateArray<byte>(15000000, pinned: true);
System.GC.Collect();
var p2 = GC.AllocateArray<byte>(15000000, pinned: true);
System.GC.Collect();
var p3 = GC.AllocateArray<byte>(15000000, pinned: true);
System.GC.Collect();
});
app.MapGet("/throwandcatchinvalidoperation", () =>
{
try
{
throw new System.InvalidOperationException();
}
catch(Exception){}
throw new System.InvalidOperationException();
});
app.MapGet("/throwargumentexception", () =>
{
throw new System.ArgumentException();
});
// Kills the web api
app.MapGet("/terminate", () =>
{
System.Environment.Exit(0);
});
// Kills the web api
app.MapGet("/stress", () =>
{
List<Thread> arr = new List<Thread>();
for(int i=0; i<50; i++)
{
arr.Add(new Thread(DoWork));
}
foreach(Thread thread in arr)
{
thread.Start();
}
});
void DoWork()
{
for(int i = 0; i<50;i++)
{
try
{
throw new System.InvalidOperationException();
}
catch(Exception){}
}
}
app.Run();
|