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
Post a Comment