I´ve getting an exception "Invalid cross-thread access." I´m developing an Silverlight application. The problem is that I´m instantiating the object (COM+ object) in one thread and trying to access from another. This is an necessary behavior for my application. So I suppose that I need to say that the interop with COM is in MTAThread mode but I can´t see the point to do this I know the problem but I can´t see the solution.
Any help?? Thanks in advance
实例守则是:
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows;
using System.Threading;
using System.Runtime.InteropServices.Automation;
using System;
namespace BackgroundWorkerTest
{
public partial class MainPage : UserControl
{
Thread backgroundThread;
dynamic _myspeech;
static readonly object locker = new object();
public MainPage()
{
InitializeComponent();
backgroundThread = new Thread(StartScanProcess);
backgroundThread.Start();
}
private void StartScanProcess(object sender, DoWorkEventArgs e)
{
StartScanProcess();
}
private void StartScanProcess()
{
lock (locker)
{
_myspeech = AutomationFactory.CreateObject("Sapi.SpVoice")
_myspeech.Volume = 100;
}
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
_myspeech.Speak(UIThreadId.Text);
}
}
}