1

I have defined a Mutex in my class (global):

static Mutex fooMutex; 

And I want to lock something so that the user is not allowed to see the effect of tapping the image more then once per 3 seconds:

private void Image_Tap_1(...) { bool isRunnng = true; try { Mutex.OpenExisting("foo"); } catch { isRunnng = false; fooMutex = new Mutex(true, "foo"); } if (!isRunnng) { fooFadeIn.Begin(); fooFadeIn.Completed += fooFadeIn_Completed; } 

And dispose on Completed:

private void fooFadeIn_Completed(...) { fooMutex.Dispose() 

But this does not work, anyone got an idea?

1
  • 3
    I'm not convinced that a mutex is the best bet here since it may lock up the GUI thread. Maybe you should just disable the image and enable it again in 3 seconds using a timer? Commented Jan 13, 2013 at 11:20

1 Answer 1

4

Rather than using a mutex or a timer, you can just store the time at which the image was last tapped:

private DateTime lastTap; private void Image_Tap_1(...) { var now = DateTime.Now; if ((now - lastTap).TotalSeconds < 3) { return; } lastTap = now; // More than 3 seconds since last tap ... } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.