WPF控件不支持控件. invokeRequired属性 [英] WPF Controls does not supported Control. invokeRequired Property

查看:186
本文介绍了WPF控件不支持控件. invokeRequired属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,在Windows应用程序中,我可以使用if(AnyControl.invokeRequired)..做点事
但是在WPF中找不到此属性
任何人都可以帮助我将此代码转换为WPF代码
代码是:

hi guys , in Windows application and i can use if(AnyControl.invokeRequired) .. do some thing
but here in WPF can not found this property
any one help my to convert this Code into WPF Code
the code is :

void buffer_TimedOut(String value)
{
    if (this.InvokeRequired)
    {
        this.BeginInvoke(new Action<String>(buffer_TimedOut), new Object[] { value });
    }
    else
    {
        if (value.Length == 13)
        {
    // Barcode!
        }
        else
        {
            // Typed text...append to Textbox f.e.
        }
    }



任何人都可以帮助我做到这一点...谢谢



any one help me in doing that ... thanks

推荐答案

对于大多数应用程序,即使在System.Windows.Forms.Control中,您也不需要它,因为此属性将始终如果使用控件从UI线程以外的任何线程中调用,则返回true;在大多数设计中,您都知道这一点;此属性仅在可以从UI线程或非UI线程调用的某些方法中使用,这种方法相对较少.

对于WPF,您需要使用类Dispatcher:
http://msdn.microsoft.com/en-us/library/system. windows.threading.dispatcher.aspx [ ^ ].

请参阅这篇文章,其中有足够的介绍:
http://msdn.microsoft.com/en-us/magazine/cc163328.aspx [ ^ ].

—SA
For most applications, you don''t need it even in System.Windows.Forms.Control, because this property will always return true if called from any thread other then the UI thread using a control, and in most designs you know that; this property is only used in some method which can be called from either UI or non-UI thread, which is relatively rare.

With WPF, you need to use the class Dispatcher:
http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.aspx[^].

Please see this article which give sufficient introduction:
http://msdn.microsoft.com/en-us/magazine/cc163328.aspx[^].

—SA


这篇关于WPF控件不支持控件. invokeRequired属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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