Silverlight背景工作者-无效的ThreadAccess [英] Silverlight Background Worker - Invalid ThreadAccess

查看:59
本文介绍了Silverlight背景工作者-无效的ThreadAccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道要为Dowork流程访问哪个线程:

我在DomainDataSource LoadedData中有以下代码

I don''t know which thread to access for the Dowork process:

I have the following code in the DomainDataSource LoadedData

<pre lang="vb">If (DataGrid.ItemsSource IsNot Nothing) Then
            Dim count As Integer = DataGrid.ItemsSource.OfType(Of Object)().Count()
            lblCount_Stat.Content = "Count: " & count
        End If




尝试在加载数据网格时尝试访问无效的线程访问




I get an Invalid Thread Access when I try to access the datagrid as it is loading

<pre lang="vb">Private Sub BackgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker.DoWork
        Dim result As String

        result = Me.DataGrid.ItemsSource.OfType(Of Object)().Count()

        e.Result = result
    End Sub


推荐答案

这是因为您试图访问在另一个线程上创建的UI元素.您必须使用Invoke来做到这一点.

http://www.silverlightshow.net/tips/How- to-invoke-method-in-the-UI-thread.aspx [
It''s because you''re trying to access a UI element that was created on another thread. You have to use Invoke to do that.

http://www.silverlightshow.net/tips/How-to-invoke-method-in-the-UI-thread.aspx[^]


您可能需要使用Dispatcher.BeginInvoke.


这篇关于Silverlight背景工作者-无效的ThreadAccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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