-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
XuanThuLab
committed
Aug 20, 2020
1 parent
a4a4257
commit 6bf8417
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
// Use IntelliSense to find out which attributes exist for C# debugging | ||
// Use hover for the description of the existing attributes | ||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "build", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/CS023_Dispose.dll", | ||
"args": [], | ||
"cwd": "${workspaceFolder}", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
}, | ||
{ | ||
"name": ".NET Core Attach", | ||
"type": "coreclr", | ||
"request": "attach", | ||
"processId": "${command:pickProcess}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "build", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"build", | ||
"${workspaceFolder}/CS023_Dispose.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "publish", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"publish", | ||
"${workspaceFolder}/CS023_Dispose.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
}, | ||
{ | ||
"label": "watch", | ||
"command": "dotnet", | ||
"type": "process", | ||
"args": [ | ||
"watch", | ||
"run", | ||
"${workspaceFolder}/CS023_Dispose.csproj", | ||
"/property:GenerateFullPaths=true", | ||
"/consoleloggerparameters:NoSummary" | ||
], | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace CS023_Dispose { | ||
class A : IDisposable { | ||
bool resource = true; | ||
public void Dispose () { | ||
Console.WriteLine ("Phương thức này gọi tự động khi hết using"); | ||
resource = false; // giải phóng tài nguyên | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
class Program { | ||
static void Main (string[] args) { | ||
|
||
// using (var a = new A ()) { | ||
// Console.WriteLine ("Do something ..."); | ||
// } | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace CS023_Dispose { | ||
|
||
public class WriteData : IDisposable { | ||
|
||
// trường lưu trạng thái Dispose | ||
private bool m_Disposed = false; | ||
|
||
private StreamWriter stream; | ||
|
||
public WriteData (string filename) { | ||
stream = new StreamWriter (filename, true); | ||
} | ||
|
||
// Phương thức triển khai từ giao diện | ||
public void Dispose () { | ||
Dispose (true); | ||
GC.SuppressFinalize (this); | ||
} | ||
|
||
// Nếu disposing = true -> Được thi hành do gọi trực tiếp (do Dispose gọi) | ||
// tài nguyên managed, unmanaged được giải phóng | ||
// nếu disposing = fale -> Được thi hành bởi phương thức hủy, chỉ cần giải phóng | ||
// các toàn nguyên unmanaged. | ||
protected virtual void Dispose (bool disposing) { | ||
if (!m_Disposed) { | ||
if (disposing) { | ||
// các đối tượng có Dispose gọi ở đây | ||
stream.Dispose(); | ||
} | ||
|
||
// giải phóng các tài nguyên không quản lý được cửa lớp (unmanaged) | ||
|
||
m_Disposed = true; | ||
} | ||
} | ||
|
||
~WriteData () { | ||
Dispose(false); | ||
} | ||
|
||
} | ||
|
||
} |