获得"跨线程操作无效"即使使用invoke方法 [英] Getting "cross-thread operation not valid" even when using invoke method

查看:116
本文介绍了获得"跨线程操作无效"即使使用invoke方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了跨线程操作无效在这里:

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
            }
        }

调试让我发现,VLC不需要调用。但作为此被访问的线程是从它上创建的线程不同

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.

我使用的是libvlc.net包装播放声音,但问题不应该存在。 我怎样才能摆脱这种异常?

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?

我使用的线程不BackgroundWorker的。

I'm using threading not backgroundworker.

感谢您!

推荐答案

听起来好像这是在libvlc.net包装的错误。

It sounds like this is a bug in the libvlc.net wrappers.

我的建议是,只是始终调用vlc.Invoke(...)。你会遭受(小)的性能损失时,是真正不需要调用,但如果你这样做,从一个单独的线程,它总是需要反正。

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.

这篇关于获得"跨线程操作无效"即使使用invoke方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆