private void grabThumbnails_UpdateProgressCallback(MediaThumb thumb) { ItemProgress += 1; }
private void grabThumbnails_UpdateProgressCallback(MediaThumb thumb) { ItemProgress += 1; }
async void Timer_Elapsed(object sender, EventArgs e) { Timer.Stop(); Point mousePos = Mouse.GetPosition(previewImage); double position = mousePos.X / previewImage.ActualWidth; Interlocked.Increment(ref nrWaitingThreads); try { MediaThumb thumbnail = await Task <MediaThumb> .Factory.StartNew(() => { Semaphore.Wait(); Interlocked.Decrement(ref nrWaitingThreads); if (nrWaitingThreads > 0 || TokenSource.IsCancellationRequested) { return(null); } return(ViewModel.getVideoPreviewThumbnail(position, TokenSource.Token)); }); if (thumbnail == null) { return; } previewImage.Source = thumbnail.Thumb; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this); adornerLayer.Remove(TimeAdorner); Size size = TimeAdorner.Size; double xLeft = mousePos.X - size.Width / 2; double xRight = xLeft + size.Width; if (xLeft < 0) { xLeft = 0; } if (xRight > previewImage.ActualWidth) { xLeft = previewImage.ActualWidth - size.Width; } TimeAdorner.Location = new Point(xLeft, previewImage.ActualHeight - size.Height); TimeAdorner.TimeSeconds = (int)thumbnail.PositionSeconds; adornerLayer.Add(TimeAdorner); } catch (Exception) { } finally { Semaphore.Release(); } }