public void HandleDAQException(DAQThreadUnhandledExceptionArgs args)
 {
     //this will be running on non ui thread
     if (args.Exception is MCAException)
     {
         //MessageBox.Show(args.Exception.ToString());
         Application.Current.Dispatcher.BeginInvoke((Action)(()=>LogException(args.Exception)));
         args.Handled = true;
     }
 }
Beispiel #2
0
        public void Acquire()
        {
            try
            {
                //Application.Current.Dispatcher.Invoke(OnSuccessfulStart);//this needs to be sync call
                OnSuccessfulStart();
                //Debug.WriteLine(MCA.GetBoardStatus());
                if (!DryMode) MCA.StartAcquisition();
                while (!shouldstop && !ShouldStopCondition())
                {
                    Thread.Sleep(PollInterval);
                    ReadoutData rd = null;
                    if (!DryMode)
                    {
                        rd = MCA.ReadData(nwaveform);
                    }
                    else
                    {
                        rd = ReadoutData.DummyData(2, 100, nwaveform, 2000, 100);
                    }

                    Application.Current.Dispatcher.BeginInvoke((Action)(() => UpdateProgress(rd)));
                }
            }
            catch (MCAException e)
            {
                DAQThreadUnhandledExceptionArgs args = new DAQThreadUnhandledExceptionArgs(e);
                this.UnhandledException(args);
                if (!args.Handled) { throw; }
            }
            finally
            {
                try
                {
                    if (!DryMode)
                    {
                        MCA.StopAcquisition();
                        //App.MCA.ClearData();
                        while (MCA.HasData)
                        {
                            ReadoutData rd = MCA.ReadData(nwaveform);
                            Application.Current.Dispatcher.BeginInvoke((Action)(() => UpdateProgress(rd)));
                        }
                    }
                }
                catch (MCAException e) //if clean up fail just log
                {
                    DAQThreadUnhandledExceptionArgs args = new DAQThreadUnhandledExceptionArgs(e);
                    this.UnhandledException(args);
                }
                finally
                {
                    Application.Current.Dispatcher.BeginInvoke(OnSuccessfulStop);
                    ready.Set();
                }
            }
        }