Skip to content

Implementation of Chapter10 process exit PR #148 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 10.21 to match book
  • Loading branch information
BenjaminMichaelis committed Jan 21, 2021
commit 3be67d3eb67838394adcdc007f89fa98db1512a2
24 changes: 13 additions & 11 deletions src/Chapter10/Listing10.21.ResourceCleanupWithIDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,20 @@ public TemporaryFileStream(string fileName)
public TemporaryFileStream()
: this(Path.GetTempFileName()) { }



~TemporaryFileStream()
{
Dispose(false);
}

public FileStream Stream { get; }
public FileInfo File { get; }

protected void Close()
{
Dispose();
}
public FileStream? Stream { get; private set; }
public FileInfo? File { get; private set; }

#region IDisposable Members
public void Dispose()
{
Dispose(true);

// Turn off calling the finalizer
//unregister from the finalization queue.
System.GC.SuppressFinalize(this);
}
#endregion
Expand All @@ -68,7 +61,16 @@ public void Dispose(bool disposing)
{
Stream?.Dispose();
}
File?.Delete();
try
{
File?.Delete();
}
catch (IOException exception)
{
Console.WriteLine(exception);
}
Stream = null;
File = null;
}

}
Expand Down