public WavePartElement(UPart part) : base() { partImageTrans = new TranslateTransform(); this.Part = part; partBitmap = BitmapFactory.New( (int)System.Windows.SystemParameters.VirtualScreenWidth, (int)UIConstants.TrackMaxHeight); partImage = new PartImage() { RenderTransform = partImageTrans, IsHitTestVisible = false }; partImage.Arrange(new Rect(0, 0, partBitmap.PixelWidth, partBitmap.PixelHeight)); partImage.Source = partBitmap; this.RemoveVisualChild(partVisual); this.AddVisualChild(partImage); if (((UWavePart)Part).Peaks == null) { worker = new BackgroundWorker() { WorkerReportsProgress = true }; worker.DoWork += BuildPeaksAsync; worker.ProgressChanged += BuildPeaksProgressChanged; worker.RunWorkerCompleted += BuildPeaksCompleted; worker.RunWorkerAsync((UWavePart)Part); } }
public WavePartElement(UPart part) : base() { partImageTrans = new TranslateTransform(); this.Part = part; partBitmap = BitmapFactory.New( (int)System.Windows.SystemParameters.VirtualScreenWidth, (int)UIConstants.TrackMaxHeight); partImage = new PartImage() { RenderTransform = partImageTrans, IsHitTestVisible = false }; partImage.Arrange(new Rect(0, 0, partBitmap.PixelWidth, partBitmap.PixelHeight)); partImage.Source = partBitmap; this.RemoveVisualChild(partVisual); this.AddVisualChild(partImage); if (((UWavePart)Part).Peaks == null) { var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Run(() => { ((UWavePart)Part).BuildPeaks(this); Dispatcher.Invoke(() => { RedrawPart(); }); }).ContinueWith((task) => { if (task.IsFaulted) { Log.Information($"{task.Exception}"); throw task.Exception; } }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, scheduler); } }