public void writetolist(Plot p)
{
lock (this) // Enter synchronization block
{
if (readerFlag)
{ // Wait until ReadFromCell is done consuming.
try
{
Monitor.Wait(this); // Wait for the Monitor.Pulse in
// ReadFromList
}
catch (SynchronizationLockException e)
{
Console.WriteLine(e);
OnError(121, e.Message);
}
catch (ThreadInterruptedException e)
{
Console.WriteLine(e);
}
}
list.Add(p);
Console.WriteLine("Element added to List By Core Team");
readerFlag = true; // Reset the state flag to say insertion to List
// is done
Monitor.Pulse(this); // Pulse tells ReadFromList that
// WriteToList is done.
} // Exit synchronization block
}