getting an exception????

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
hi,

i am trying the following code for my WPF application :

using System;<br/>
using System.Collections;<br/>
using System.Text;<br/>
using System.Windows;<br/>
using System.Windows.Controls;<br/>
using System.Windows.Data;<br/>
using System.Windows.Documents;<br/>
using System.Windows.Input;<br/>
using System.Windows.Media;<br/>
using System.Windows.Media.Imaging;<br/>
using System.Windows.Shapes;<br/>
using System.Windows.Navigation;<br/>
using System.Media;<br/>
using Phidgets;<br/>
using Phidgets.Events;<br/>
namespace MG<br/>
{<br/>
<br/>
/// <summary><br/>
/// Interaction logic for MainWindow.xaml<br/>
/// </summary><br/>
public partial class MainWindow : Window<br/>
{<br/>
private InterfaceKit ifKit;<br/>
<br/>
<br/>
public MainWindow()<br/>
{<br/>
this.InitializeComponent();<br/>
<br/>
// Insert code required on object creation below this point.<br/>
<br/>
try<br/>
{<br/>
ifKit = new InterfaceKit();<br/>
ifKit.open();<br/>
ifKit.waitForAttachment(3000);<br/>
textBox1.Text = "connected";<br/>
}<br/>
catch<br/>
{<br/>
textBox1.Text = "Not Connected";<br/>
}<br/>
<br/>
ifKit.SensorChange += new SensorChangeEventHandler(ifKit_SensorChange);<br/>
}<br/>
void ifKit_SensorChange(object sender, SensorChangeEventArgs e)<br/>
{<br/>
textBox2.Text = "Index " + e.Index;
<span style="text-decoration:underline // Exception occurs here
<br/>
}<br/>
<br/>
}<br/>
}

but when i run this code i am getting the following exception at the highlighted part of the code:
"The calling thread cannot access this object because a different thread owns it."

the same code when i run in the windows form application by hooking the event handler at loading of the form and with the same method defined it runs fine.

can any one help me out???


View the full article
 
Back
Top