one at a time access to a function!
Hi I have a c# windows form written in .Net 4. In the application a timer event calls a function and all is fine. however I have updated the app so its a single instance app and when a second instance is called it triggers the same function as the timer in the first instance. I believe I'm getting an issue when t开发者_Go百科he timer has called the function and a second instance causes the first instance to enter the same function simultaneously. does this make sense!!!
So how do I queue the calls to the function so the second process calling it waits until the first one has exited and if it doesn't gain access within X seconds make it return an error? do I do all of this within the function which is a Static one?
As this may not make sense, even to me! if I had 2 timers in a project and both call the same static function how would I stop both calling the function at the same time and queue them up!
I have started reading about Mutex but not sure how I would uses them and if they would go out of scope!?
Thanks
Use lock in the function to ensure the exclusive access.
精彩评论