06-11-2007 08:53 PM
//that the object marshals callbacks across threads appropriately.
mbSession.SynchronizingObject =
this;where this is the form that this code resides in.
I am writing an app with lower level classes(eg Oven.cs) that will have the serial sessions defined in them. The Form is not available, and 'this' in Oven.cs gives a compiler error :
Cannot implicitly convert type 'ReceiveSerial.Oven' to 'System.ComponentModel.ISynchronizeInvoke'
I am seeing somewhat random errors and deadlocks that I suspect are related to commenting this line out. What objects can be coverted to ISynchronizeInvoke ? Or, can I write supporting code into my Oven class that will keep the object synchronized.
This looks easier in VS2005; but I am stuck with my client's VS2003 license at this point.
Tom
06-12-2007 07:56 PM
It sounds like you may be
receiving undefined behavior as explained in the National Instruments -> VISA
-> Documentation -> NI-VIAS .NET Framework 2.0 Help section:
ms-help://NI.MeasurementStudio.2005/NINETMain/XML/Events_Callbacks_ThreadSafety.html
"Since Windows Forms controls can only be accessed from the UI thread, you
cannot access Windows Forms controls in your callback if you set SynchronizeCallbacks
to false. Accessing Windows Forms controls from threads other than the
UI thread results in undefined behavior. In .NET Framework 2.0, some Windows
Forms controls throw exceptions when accessed from other threads."
Regards,
06-14-2007 01:15 PM
06-15-2007 03:19 PM
Thanks guys.
My Oven class does indeed throw an event up to the Main form - which then updates a NI graph component, LEDs, and the like. It works almost all of the time-- but I don't trust it.
What code do I need in the Oven class to enable a SynchronizationObject property? Is there an example installed with a similar architecture?
06-15-2007 03:50 PM
06-18-2007 01:24 PM
Thanks, Dave
That seems to have done the trick. I won't know for sure until it runs a couple of hours.
Tom