Z
Zürcher See
I have a main form, which pop other forms (children forms).
The children forms have a delegate of a function, let call it EndFunction,
of the main form, that they call when they ends their work.
By closing the main form, it force the children forms to close too, and
before to close himself wait until the last children form has closed.
When the children forms are force to close, they will call so rush the
EndFunction that I have a synchronization problem with it.
I tried to use the Monitor.Enter / Exit and the lock(..){} in the
EndFunction, but I had a lock in the application.
By implementing a very simple lock mechanism it work very well:
private bool busy=false;
public void EndFunction()
{
while(busy) System.Threading:Thread.Sleep(100);
busy=true;
...
busy=false;
}
Is that the only way to synchronize a bit of code without lock the entire
object?
The children forms have a delegate of a function, let call it EndFunction,
of the main form, that they call when they ends their work.
By closing the main form, it force the children forms to close too, and
before to close himself wait until the last children form has closed.
When the children forms are force to close, they will call so rush the
EndFunction that I have a synchronization problem with it.
I tried to use the Monitor.Enter / Exit and the lock(..){} in the
EndFunction, but I had a lock in the application.
By implementing a very simple lock mechanism it work very well:
private bool busy=false;
public void EndFunction()
{
while(busy) System.Threading:Thread.Sleep(100);
busy=true;
...
busy=false;
}
Is that the only way to synchronize a bit of code without lock the entire
object?