捕获异常会产生新流程

时间:2018-09-18 15:02:03

标签: c#

似乎每次捕获到异常时,都会创建一个新的流程实例。但这对我的朋友来说不会发生。是什么原因造成的?

using System;
using System.Diagnostics;

namespace ConsoleApp1 {
  class Program {
    static void Main(string[] args) {
      Console.WriteLine("Number of process instances: " + Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length);
      try {
        int b = 0;
        int a = 1 / b;
      } catch {
      };
      Console.WriteLine("Number of process instances: " + Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length);
      Console.ReadLine();
    }
  }
}

代码产生以下输出:

Number of process instances: 1
Number of process instances: 2

但是我已经将代码传递给了朋友。他得到以下输出:

Number of process instances: 1
Number of process instances: 1

我正在使用VS2017

0 个答案:

没有答案