我正在编写labVIEW VI,以便能够处理从C#库引发的异常。我不知道如何使用错误群集读取异常消息以及如何处理退出应用程序。

我以这种方式编写了C#代码:

// Make use of generic System library calls in this code.
using System.ComponentModel;

// Define the namespace for the following classes.
namespace NETEvents
{
    // ProduceMyEvent is a class that will fire the event.
    public class ProduceMyEvent : INotifyPropertyChanged
    {
        //Declare an internal variable. We will use this to fire events upon a changed value.
        //Note that this value is private to the ProduceMyEvent class.
        private int x;
        // Fire the event when the value of x changes.
        public int xValue
        {
            //Get the value of x.
            get { return x; }
            //Set x to be the new value and fire off the new event!
            set { x = value;

                if (x < 0) {
                    throw new System.Exception("x must be larger than 0 \n");
                }

                OnPropertyChanged("xValue"); }
        }

        // INotifyPropertyChanged implementation
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
        }
        #endregion
    }
}

使用此代码,如果x在VI中设置为负,则引发异常。但是,通过下面显示的我的labview实现,未捕获到异常。错误状态为true,并且源为空。如何使用错误群集读取C#引发的异常?

c# - LabVIEW : handling exceptions thrown from C# on VI-LMLPHP

最佳答案

异常处理在这里详细说明:https://forums.ni.com/t5/LabVIEW/Catch-Exception-in-c-with-Net-Assembly-Built-in-Labview/td-p/3360501

关于c# - LabVIEW : handling exceptions thrown from C# on VI,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49498813/

10-12 20:57