Created
July 11, 2011 22:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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