I'm developing an application that use an external device to communicate with an electronic board using USB protocol. When I want to display results obtained during communication inside TextBlock an error msg appears saying
The calling thread cannot access this object because a different thread owns it
How could I stop this thread or print the appropriate info in my textblock?
Here the code used :
/// ******************************************************************
/// <summary>
/// RX_Thread
///
/// Description:
/// Second thread which receives data from configured receive port
/// (CANDemo_RxChannel)of XL interface.
/// </summary>
/// ******************************************************************
#region EVENT THREAD (RX)
public void RX_Thread()
{
// object to be fill with received data
XLClass.xl_event receivedEvent = new XLClass.xl_event();
// result of XL driver func. calls
XLClass.XLstatus xlStatus = XLClass.XLstatus.XL_SUCCESS;
// WaitForSingleObject values
WaitResults waitResult = new WaitResults();
// note: this thread is destroyed by MAIN
while (true)
{
// wait for hardware events
waitResult = (WaitResults)WaitForSingleObject(CANDemo_RxChannel.eventHandle, 1000);
// if event occured...
if (waitResult != WaitResults.WAIT_TIMEOUT)
{
// ...init xlStatus first
xlStatus = XLClass.XLstatus.XL_SUCCESS;
// afterwards: while hw queue is not empty...
while (xlStatus != XLClass.XLstatus.XL_ERR_QUEUE_IS_EMPTY)
{
// ...receivedata from hardware queue
xlStatus = CANDemo_RxChannel.xlReceive(ref receivedEvent);
// if receiveing succeed...
if (xlStatus == XLClass.XLstatus.XL_SUCCESS)
{
// ...print rx data
string BigContained = CANDemo.XL_GetEventString(receivedEvent);
//GetInfo(BigContained);
// ((XLClass.xl_event)xlEventCollection.xlEvent[0]).tagData.can_Msg.id = 0x74D;
if (receivedEvent.tagData.can_Msg.id == 0x76D)
{
if (receivedEvent.tagData.can_Msg.data[0] == Convert.ToByte(2) && receivedEvent.tagData.can_Msg.data[1] == Convert.ToByte(80) && receivedEvent.tagData.can_Msg.data[2] == Convert.ToByte(250))
{
// i want to writ the data in my Texbloxk but i get error :
txtframeContainer.Text = "Enter in diagnostic mode SupplierSpecific --> Ok ";
}
}
}
}
}
// no event occured
}
}
#endregion
/// ------------------------------------------------------------------
waiting for your feedback guys...