static void Main(string[] args) { // 4 - chamada ClasseSingleton.getInstance(). //Singleton singCliente1 = Singleton.getInstance("Instancia 1"); //singCliente1._valor = 10; //Singleton singCliente2 = Singleton.getInstance("Instancia 2"); ////Exibe o 10 //singCliente2.ExibirValor(); //singCliente2._valor = 20; ////Exibe o 20 //singCliente1.ExibirValor(); Singleton_2 singCliente3 = Singleton_2.getInstance(); singCliente3._valor = 10; //Nova thread Thread teste = new Thread(TesteThread); teste.Start(); //Exibe o 10 teste.Join(); //Final thread Singleton_2 singCliente4 = Singleton_2.getInstance(); //Exibe o 100 singCliente4.ExibirValor(); singCliente4._valor = 20; //Exibe o 20 singCliente3.ExibirValor(); Console.ReadKey(); }
private static void TesteThread() { Console.WriteLine("Inicio Thread"); Singleton_2 singCliente5 = Singleton_2.getInstance(); //Exibe o 10 singCliente5.ExibirValor(); singCliente5._valor = 100; Console.WriteLine("Fim Thread"); }