English 中文(简体)
电话线穿透无法进入这个物体,因为不同的透镜是它自己的。
原标题:The calling thread cannot access this object because a different thread owns it

我正在使用以下法典。

public partial class SettingApp
{
    public SettingApp()
    {
        InitializeComponent();
        Parallel.Invoke(SetDataInTextBox);
    }

    private void SetDataInTextBox()
    {
        txtIncAns.Text = Properties.Settings.Default.IncludeAN;
        txtIncAuthor.Text = Properties.Settings.Default.IncludeAutt;
        txtIncQuo.Text = Properties.Settings.Default.IncludeQU;
        txtIncSpBegin.Text = Properties.Settings.Default.IncludeSP;
    }
}

该方案有以下错误:

The calling thread cannot access this object because a different

它已经拥有。

正确方式

update :

是否正确:

   public partial class SettingApp
{
    private delegate void SetDataInTextBoxDelegate();
    public SettingApp()
    {
        InitializeComponent();

        txtIncAns.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new SetDataInTextBoxDelegate(SetDataInTextBox));
    }

     private void SetDataInTextBox()
    {
        txtIncAns.Text = Properties.Settings.Default.IncludeAN;
        txtIncAuthor.Text = Properties.Settings.Default.IncludeAutt;
        txtIncQuo.Text = Properties.Settings.Default.IncludeQU;
        txtIncSpBegin.Text = Properties.Settings.Default.IncludeSP;
    }
}
最佳回答

只有国际宇宙航行联合会的校对才能查阅国际宇宙航行联合会的内容,而国际宇宙航行联合会的构思正是这些内容的<编码>txt。 情况就是如此。 <代码>Parallel。 Invoke <>code> is in You case not the UI thread, so the exception is band when Youtries to access the .Text property on the control.

You need to marshal the call across to the UI thread. In WinForms, controls have various ways to help you do this:

if (myControl.InvokeRequired)
{
    myControl.Invoke(...);
}
else
{
    myControl.Text = "something";
}

MSDN有一篇文章,有这方面的实例(VS2010):

http://msdn.microsoft.com/en-us/library/757y83z4(v=VS.100)。

<><>Update 1:

森林伙伴模式类似,但包括派遣者:

myControl.Dispatcher.Invoke(...);

<><>上> 当然,我们认为,在这里甚至不需要使用多读法。 我会猜测,使用多面部分的间接费用超过了你最终呼吁的代码。 简单地从本节中删除多管线的使用,并直接确定特性:

    public SettingApp()
    {
        InitializeComponent();
        SetDataInTextBox();
    }

    private void SetDataInTextBox()
    {
        txtIncAns.Text = Properties.Settings.Default.IncludeAN;
        txtIncAuthor.Text = Properties.Settings.Default.IncludeAutt;
        txtIncQuo.Text = Properties.Settings.Default.IncludeQU;
        txtIncSpBegin.Text = Properties.Settings.Default.IncludeSP;
    }
问题回答

正如阿达姆所说,只有统一私法网的透镜才能进入统一私法分子。 在计生联的情况下,请使用<条码>myControl.Dissigner.Invoke()。

由于所有这些电话都将在国联线上援引,你应当删除<条码>。 Invoke(并直接使用这种方法。

只是另一项建议。 我将着手把你的文本箱装入一个类别的财产,即使你不希望采用完整的多国公司设计,但具有约束力的数据是你在世界森林论坛中的朋友。 然后,如果你需要翻新,那么当财产发生变化时,世界森林基金会将着手对地盘进行更新控制,即使财产在另一条路面上发生变化。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签