Getting “cross-thread operation not valid” even when using invoke method

空扰寡人 提交于 2019-12-11 03:32:04

问题


I get the "cross-thread operation not valid" here:

if ( vlc.State == VlcPlayerControlState.PLAYING )
        {
            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!


回答1:


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.



来源:https://stackoverflow.com/questions/1954140/getting-cross-thread-operation-not-valid-even-when-using-invoke-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!