public void ListenDemo() { Task.Run(() => { isWorking = true; NotifyOfPropertyChange(() => CanListenDemo); NotifyOfPropertyChange(() => CanBuildKeySound); NotifyOfPropertyChange(() => CanOpenSoundfont2); int instrument; int key; if (!IsDrum) { key = PitchIdx + (OctaveIdx + 1) * 12; instrument = InstTypeIdx * 8 + InstNameIdx; } else { instrument = 0; key = 35 + InstNameIdx; } if (key > 127) { MessageBox.Show("No such key"); } else { string filename = MusicTheory.GetFileName(instrument, key, (int)Bpm, (int)Length, Volume, IsDrum); string midiFilename = $"{System.IO.Path.GetTempPath()}\\{filename}.mid"; string wavFilename = $"{System.IO.Path.GetTempPath()}\\{filename}.wav"; maker.GenKeySoundMidi(midiFilename, instrument, key, Bpm, Length, Volume, IsDrum); maker.SetOutputFilename(wavFilename); maker.RenderMiditoWav(midiFilename); System.Media.SoundPlayer player = new System.Media.SoundPlayer(wavFilename); player.Play(); } isWorking = false; NotifyOfPropertyChange(() => CanListenDemo); NotifyOfPropertyChange(() => CanBuildKeySound); NotifyOfPropertyChange(() => CanOpenSoundfont2); }); }