S
ste
this code not work: it is no possible Exit from Monitor
Why ?
thank
ste
////////
using System;
using System.Collections;
using System.Threading;
namespace consoleProtection
{
class Class1
{
ArrayList _obj = new ArrayList();
[STAThread]
static void Main(string[] args)
{
Class1 newClass1 = new Class1();
newClass1.go();
Sleep(15000);
}
public void go()
{
Thread _th1 = new Thread(new ThreadStart(this.enter));
_th1.Start();
Thread.Sleep(100);
Thread _th2 = new Thread(new ThreadStart(this.exit));
_th2.Start();
Thread.Sleep(100);
Thread _th3 = new Thread(new ThreadStart(this.enter));
_th3.Start();
}
void enter()
{
Console.WriteLine("try to enter");
Monitor.Enter(_obj);
Console.WriteLine("enter");
}
void exit()
{
Monitor.Exit(_obj);
Console.WriteLine("exit");
}
}
}
Why ?
thank
ste
////////
using System;
using System.Collections;
using System.Threading;
namespace consoleProtection
{
class Class1
{
ArrayList _obj = new ArrayList();
[STAThread]
static void Main(string[] args)
{
Class1 newClass1 = new Class1();
newClass1.go();
Sleep(15000);
}
public void go()
{
Thread _th1 = new Thread(new ThreadStart(this.enter));
_th1.Start();
Thread.Sleep(100);
Thread _th2 = new Thread(new ThreadStart(this.exit));
_th2.Start();
Thread.Sleep(100);
Thread _th3 = new Thread(new ThreadStart(this.enter));
_th3.Start();
}
void enter()
{
Console.WriteLine("try to enter");
Monitor.Enter(_obj);
Console.WriteLine("enter");
}
void exit()
{
Monitor.Exit(_obj);
Console.WriteLine("exit");
}
}
}