Why can't you use the Timer.Elapsed event?
Just remember that the Elapsed callback occurs in the Worker Thread, which makes it impossible to update the user interface. Therefore, you should use SynchronizationContext to direct UI update actions to the appropriate thread.
private SynchronizationContext _context = SynchronizationContext.Current;
void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
using (Image<Bgr, byte> frame = capture.QueryFrame())
{
if (frame != null)
{
this._context.Send(o =>
{
using (var stream = new MemoryStream())
{
frame.Bitmap.Save(stream, ImageFormat.Bmp);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(stream.ToArray());
bitmap.EndInit();
webcam.Source = bitmap;
}
},
null);
}
}
}
, , DispatcherInactive event:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(Hooks_DispatcherInactive);
}
void Hooks_DispatcherInactive(object sender, EventArgs e)
{
using (Image<Bgr, byte> frame = capture.QueryFrame())
{
if (frame != null)
{
using (var stream = new MemoryStream())
{
frame.Bitmap.Save(stream, ImageFormat.Bmp);
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.StreamSource = new MemoryStream(stream.ToArray());
bitmap.EndInit();
webcam.Source = bitmap;
};
}
}
}