c# - Windows Store Application Metronome Stop Button Not Working -


hello there developing windows store app.

first of all, here code:

public class tickargs : eventargs {     public datetime time { get; set; } }  public class metronome {     private dispatchertimer _timer;     public event tickhandler tick;     public delegate void tickhandler(metronome m, tickargs e);      public metronome()     {         _timer = new dispatchertimer();         _timer.tick += timer_tick;     }      private void timer_tick(object sender, object e)     {         if (tick != null)         {             tick(this, new tickargs { time = datetime.now });         }     }      public void start(int bbm)     {         _timer.stop();         _timer.interval = timespan.fromseconds(60 / bbm);         _timer.start();     }     public void stop()     {         _timer.stop();         _timer.start();     } }  public class listener {     public void subscribe(metronome m, mediaelement mmx)     {         m.tick += (mm, e) => mmx.play();     }     public void unsubscribe(metronome m, mediaelement mmx)     {         m.tick += (mm, e) => mmx.stop();      } } 

to start metronome use these codes:

l.subscribe(m, mediaelement); m.start(120); 

this works fine.

to stop metronome use these codes:

l.unsubscribe(m, mediaelement); m.stop(); 

metronome stops but if try start again, not start. should do?

i appreciate helps.

my regards...

okay, have done you've subscribed metronome 2 handlers, each happening on tick timer.

first of all, make static method in listener class event handler can remove.

private static void tickplay(object sender, eventargs e) {     mmx.play(); } 

then, in subscribe method, say:

m.tick += tickplay; 

lastly, unsubscribe method, say:

m.tick -= tickplay; 

this way won't keep going play/stop ever tick interval.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -