pigrew / HP3478Ctrl

HP 3478A Utility
BSD 2-Clause "Simplified" License
4 stars 2 forks source link

Application crashes with unhandled exception #1

Closed maxwellhadley closed 7 years ago

maxwellhadley commented 7 years ago

I get an immediate application crash whenever I try to read the calibration data. My 3478A is at VISA address GPIB1::4::INSTR, but it doesn't make a difference which address I use. I'm running Windows 7, using the Keysight IO suite latest version (17.3.21412.2).

Running under VS2015 debugger, I get the following exception details:

System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=The calling thread cannot access this object because a different thread owns it.
  Source=WindowsBase
  StackTrace:
       at System.Windows.Threading.Dispatcher.VerifyAccess()
       at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
       at System.Windows.Controls.TextBox.get_Text()
       at HP3478Ctrl.MainWindow.<GetCalData>b__1_0() in C:\Users\max\progs\CS\HP3478Ctrl\HP3478Ctrl\HP3478Ctrl\MainWindow.xaml.cs:line 26
       at System.Threading.Tasks.Task`1.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: 
iainkwhite commented 7 years ago

I think this is due to HP3478A.ReadCalibration( ) call running in a different thread to other classes (Write, Verify).

I had a go at rewriting this to put the ReadCalibration in the same thread as the others You can see my updates at iainkwhite/HP3478Ctrl which I forked from pigrew/HP3478Ctrl

I suggest you try this out in Read mode only! I will ask Pigrew to review it and maybe include in his version