Getting "cross-thread operation not valid" even when using invoke method
I get the "cross-thread operation not valid" here:
if ( vlc.State == VlcPlayerControlState.PLAYING )
{
开发者_C百科 if ( vlc.InvokeRequired )
{
vlc.Invoke( new MediaPlayerNoParameterDelegate( vlc.Stop ) );
}
else
{
vlc.Stop(); // debugger points here
}
}
Debugging shows me that vlc doesn't require invoking. but the thread from which this is accessed is different from the thread it was created on.
I'm using the libvlc.net wrapper to play sound, but the problem should not be there. How can I get rid of this exception?
I'm using threading not backgroundworker.
Thank you!
It sounds like this is a bug in the libvlc.net wrappers.
My suggestion would be to just always call vlc.Invoke(...). You'll suffer a (small) performance hit when the invoke is truly not required, but if you're doing this from a separate thread, it will always be required anyways.
精彩评论