Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created July 11, 2011 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaliy/1076966 to your computer and use it in GitHub Desktop.
Save chaliy/1076966 to your computer and use it in GitHub Desktop.
Example of the code, that runs in child AppDomain. Main goal is to remove shared static state between executions.
using System;
using System.Diagnostics;
public class Program
{
public static class Runner
{
public static int Test1 = 0;
public static void CodeInChildAppDomain()
{
Console.WriteLine("Test {0} + {1}", AppDomain.CurrentDomain.FriendlyName, ++Test1);
}
}
static void Main()
{
var s = new Stopwatch();
s.Start();
for (var i = 0; i < 1000; i++)
{
var appDomain = AppDomain.CreateDomain("SecondAppDomain" + i);
appDomain.DoCallBack(() =>
{
Runner.CodeInChildAppDomain();
Runner.CodeInChildAppDomain();
});
}
s.Stop();
Console.WriteLine("Average: {0}ms", s.Elapsed.TotalMilliseconds / 1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment