Answer the question
In order to leave comments, you need to log in
C# why does the "called object has been disconnected from clients" error occur?
Good day!
While studying the manual on the basics of operating systems, I came across a problem that occurs when using lock statements; monitor.enter()..., ; etc.
More specifically
class Program
{
static int Runs = 0;
static object block = new object();
static void Main()
{
Thread t2 = new Thread(new ThreadStart(Method))
{
Name = "Thread 2"
};
Thread t3 = new Thread(new ThreadStart(Method))
{
Name = "Thread 3"
};
t2.Start();
t3.Start();
Console.ReadLine();
}
public static void Method()
{
try
{
Monitor.Enter(block);
int Temp = Runs;
Temp++;
Console.WriteLine(Thread.CurrentThread.Name + " {0}", Temp);
Thread.Sleep(1000);
Runs = Temp;
}
finally
{
Monitor.Exit(block);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question