I'm trying to make playlist, where music plays one after another. I need to Dispose()
Audio
, when it finishes, because memory leak will occur. I wrote this code:
Audio a = new Audio(@"Music\Title.ogg");
a.Ending += new EventHandler((sender, e) => { (sender as Audio).Dispose(); });
a.Play();
The problem is that I have System.AccessViolationException
in Application.Run(new MainForm());
: Attempted to read or write protected memory. This is often an indication that other memory is corrupt
. It happens in ending event handler right after music finishes playing.
So, how can I play some music files one after another and dispose previous audio afer it finishes?