Catch exceptions thrown by FileStream.Dispose()

This commit is contained in:
Genteure 2021-05-25 21:52:50 +08:00
parent ee7546da3d
commit ce064f1f07
2 changed files with 22 additions and 5 deletions

View File

@ -100,8 +100,14 @@ namespace BililiveRecorder.Core.Recording
this.logger.Warning(ex, "Error calling OnRecordFileClosed");
}
file.Dispose();
stream.Dispose();
try
{ file.Dispose(); }
catch (Exception ex)
{ this.logger.Warning(ex, "关闭文件时发生错误"); }
try
{ stream.Dispose(); }
catch (Exception) { }
this.OnRecordSessionEnded(EventArgs.Empty);

View File

@ -40,8 +40,11 @@ namespace BililiveRecorder.Flv.Writer
if (this.stream is null)
return false;
this.stream.Close();
this.stream.Dispose();
try
{ this.stream.Dispose(); }
catch (Exception ex)
{ this.logger?.Warning(ex, "关闭文件时发生错误"); }
this.stream = null;
return true;
@ -174,7 +177,15 @@ namespace BililiveRecorder.Flv.Writer
{
if (disposing)
{
this.stream?.Dispose();
try
{
this.stream?.Dispose();
}
catch (Exception ex)
{
this.logger?.Warning(ex, "关闭文件时发生错误");
}
this.stream = null;
}