跳到主要内容

小技巧

  1. VM安装目录

Samples内包含C#,QT,VC应用程序

Documetnations内包含C#和C语言的帮助文档

  1. 错误码
        private void button4_Click(object sender, EventArgs e)
{
try
{
VmSolution.Load(textBox1.Text);
listBox1.Items.Add("方案加载成功.");
listBox1.TopIndex = listBox1.Items.Count - 1;
}
catch (VmException ex)
{

MessageBox.Show("VM SDK异常:" + Convert.ToString(ex.errorCode, 16));
}
catch (Exception ex) {
MessageBox.Show("系统异常:"+ex.Message);
}

}
  1. 资源管理

程序启动时杀死进程,关闭VM

        public Form1()
{
KillProcess("VisionMasterServerApp");
KillProcess("VisionMaster");
KillProcess("VmModuleProxy.exe");
InitializeComponent();

}

private void KillProcess(string strKillName)
{
foreach (var item in System.Diagnostics.Process.GetProcesses())
{
if (item.ProcessName.Contains(strKillName))
{
try
{
item.Kill();
item.WaitForExit();
}
catch (Exception ex)
{

Console.WriteLine(ex.Message);
}
}
}
}

程序关闭时释放资源

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
VmSolution.Instance.Dispose();
}