Windows Store App Metronome Error
I have got a Windows Store C# application. I wanted to add a metronome to
this app. So i did. It works well. But lately, i've faced a really strange
error in metronome ticking. A strange delay(or misfire not sure how to
call it) in metronome ticking happens if i move my mouse onto listview,
textbox, textblock and other smilar objects. This error is more noticable
when i bring bpm close to 200. I could not figure out how to fix this.
Here is my metronome code:
public class TickArgs : EventArgs { public DateTime Time { get; set; } }
public class Metronome
{
public 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)
{
int x = (int)60000 / bbm;
_timer.Interval = new TimeSpan(0, 0, 0, 0, x);
_timer.Start();
}
public void Stop()
{
_timer.Stop();
}
}
public class Listener
{
public void Subscribe(Metronome m, MediaElement mmx)
{
m.Tick += (mm, e) => mmx.Play();
}
}
And my click event for metronome start button:
bpm = int.Parse(tbMetronomeSpeed.Text);
l.Subscribe(m, mMediaElement); //m is declared outside of click event. It
is Metronome object. And l is Listener object. And mMediaElement is the
media element declared in xaml part of object. It is ticking sound.
m.Start(bpm);
I would appreciate your helps.
My regards...
No comments:
Post a Comment