Monday, April 28, 2014

What is proper way to prevent two separate threads from running at same time?

Hi, you can try this:




private object _locker = new object();

private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
lock (this._locker)
{
...do timer stuff....
}
}

void DoStuff()
{
lock (this._locker)
{
...do my stuff...
}
}


No comments:

Post a Comment