Vlc.DotNet freezes (don't call Vlc.DotNet from a Vlc.DotNet callback) - ZeBobo5/Vlc.DotNet GitHub Wiki
One of the most common issue reported is that Vlc.DotNet freezes under certain conditions.
Vlc.DotNet uses libvlc under the hood. When libvlc calls a code, it is running in libvlc's thread. In that thread, if you call libvlc code, the libvlc code will deadlock because it waits for your method to return.
You need to make sure that your method returns control to libvlc so that it can execute your request.
For example, let's say you want the video to loop, and you do something like this
public void MediaEndReached(object sender, EventArgs args)
{
this.MediaPlayer.Play("<another file>");
}
you will experience deadlocks.
Instead, do something like this:
public void MediaEndReached(object sender, EventArgs args)
{
ThreadPool.QueueUserWorkItem(_ => this.MediaPlayer.Play("<another file>"));
}
This ensures that your code is executed asynchronously on another thread, and control is correctly returned to libvlc.