2011-07-03 6 views

Odpowiedz

10

jest za dziedziny zastosowania, jak dowodzi tego np

public class Foo 
{ 
    public static string Bar { get; set; } 
} 

public class Test 
{ 
    public Test() 
    { 
     Console.WriteLine("Second AppDomain: {0}", Foo.Bar); 
    } 
} 

class Program 
{ 
    static void Main() 
    { 
     // Set some value in the main appdomain 
     Foo.Bar = "bar"; 
     Console.WriteLine("Main AppDomain: {0}", Foo.Bar); 

     // create a second domain 
     var domain = AppDomain.CreateDomain("SecondAppDomain"); 

     // instantiate the Test class in the second domain 
     // the constructor of the Test class will print the value 
     // of Foo.Bar inside this second domain and it will be null 
     domain.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Test"); 
    } 
} 
+0

Dzięki. Najlepsza odpowiedź na świecie! – Harindaka

+1

Kiedy próbuję uruchomić przykładowy program, otrzymuję wyjątek TypeLoadException z komunikatem Nie można załadować typu "Test" z zestawu "ConsoleApplication1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null". HResult to 80131522. – DWright

0

jest ograniczony do AppDomain Innymi słowy, zmienna występuje jako oddzielna wartość w każdym AppDomain.

Powiązane problemy