private void Initialize(AudioPlayer audioPlayer, SpectrumVisualizer element) { Task.Run(() => { var track = audioPlayer.CurrentlyPlaying; var callerElement = element; var result = audioPlayer.CalculateSpecterumData(callerElement.BandCount); lock (VisualizersData) { if (!VisualizersData.TryGetValue(track, out List <TimeSpectrumData> data)) { VisualizersData.Add(track, result); } else { VisualizersData[track] = result; } } }); }