Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApplication19
- {
- class Account
- {
- private static Object thisLock = new Object();
- public void Withdraw()
- {
- lock (thisLock)
- {
- Console.WriteLine("1");
- Thread.Sleep(5000);
- }
- }
- }
- class Test
- {
- static void Main()
- {
- Account a = new Account();
- Thread t = new Thread(a.Withdraw);
- t.Start();
- Account b = new Account();
- Thread t2 = new Thread(b.Withdraw);
- t2.Start();
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment