Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Lock
- {
- class Program
- {
- static void Main(string[] args)
- {
- var account = new Account();
- Task.Run(() => Distribute(account));
- Thread.Sleep(1000);
- //Monitor.Enter(account);
- Console.WriteLine("monitored");
- Monitor.Exit(account);
- Console.WriteLine("exit");
- Task.Run(() => Distribute(account));
- Thread.Sleep(30000);
- }
- public static void Distribute(Account account)
- {
- lock (account)
- {
- Console.WriteLine("locked");
- Thread.Sleep(10000);
- Console.WriteLine("unlocked");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement