C#程序异常关闭时的捕获

2019-12-30 19:46:47刘景俊

出错的程序:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DemoException
{
  public partial class FrmMain : Form
  {

    public FrmMain()
    {
      InitializeComponent();
    }

    private void FrmMain_Load(object sender, EventArgs e)
    {
      
    }

    private void btnTestUI_Click(object sender, EventArgs e)
    {
      int a = 0;
      int c = 10 / a;
    }

    private void btnTest2_Click(object sender, EventArgs e)
    {
      Thread t = new Thread(new ThreadStart(() =>
      {
        int a = 0;
        int c = 10 / a;
      }));
      t.IsBackground = true;
      t.Start();
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到c#教程频道。