Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 停止执行,关闭表单并返回给调用者_C#_Winforms - Fatal编程技术网

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语句?添加更多代码,我们无法从您发布的内容中判断执行的范围。有时我会惊讶于最简单的解决方案是如何避开我的!完美的非常感谢。