-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingletonTwo.cs
More file actions
38 lines (35 loc) · 927 Bytes
/
SingletonTwo.cs
File metadata and controls
38 lines (35 loc) · 927 Bytes
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Singleton
{
class SingletonTwo
{
public static SingletonTwo Instance()
{
lock (objLock)
{
if (m_Instance == null)
{
m_Count++;
Console.WriteLine($"Création de l'instance Count={m_Count}");
m_Instance = new SingletonTwo();
Task.Delay(1000).Wait();
}
return m_Instance;
}
}
private static readonly object objLock = new object();
private static SingletonTwo m_Instance;
private static int m_Count;
private SingletonTwo()
{
}
public void SomeMethod(string Msg)
{
Console.WriteLine($"{Msg}");
}
}
}