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