C# 停止执行,关闭表单并返回给调用者
我在子窗体上有一个保存数据记录的方法。如果遇到某些错误,我希望关闭子窗体并停止当前方法中的执行,然后返回主窗体。当我使用这个时。关闭();表单关闭,但方法在关闭表单中的执行不会停止 父窗体代码:C# 停止执行,关闭表单并返回给调用者,c#,winforms,C#,Winforms,我在子窗体上有一个保存数据记录的方法。如果遇到某些错误,我希望关闭子窗体并停止当前方法中的执行,然后返回主窗体。当我使用这个时。关闭();表单关闭,但方法在关闭表单中的执行不会停止 父窗体代码: SavePermanentRecord spr = new SavePermanentRecord(this); spr.Show(); if(path == null) { MessageBox.Show("There was a problem saving the file to the p
SavePermanentRecord spr = new SavePermanentRecord(this);
spr.Show();
if(path == null)
{
MessageBox.Show("There was a problem saving the file to the path: \r" + basePath + folderName);
this.Close();
//I need the method to stop here and any other processing in this form halted.
}
子表单代码:
SavePermanentRecord spr = new SavePermanentRecord(this);
spr.Show();
if(path == null)
{
MessageBox.Show("There was a problem saving the file to the path: \r" + basePath + folderName);
this.Close();
//I need the method to stop here and any other processing in this form halted.
}
如何停止执行并关闭当前(子)代码并返回父窗体?调用该行后,代码仍将继续执行。要停止它,只需输入
return代码>在它之后
if(path == null)
{
MessageBox.Show("There was a problem saving the file to the path: \r" + basePath + folderName);
return;
}
在this.Close()之后添加一个return语句?添加更多代码,我们无法从您发布的内容中判断执行的范围。有时我会惊讶于最简单的解决方案是如何避开我的!完美的非常感谢。