Skip to content
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

[EC88] Dispose resource asynchronously #44

Closed
Djoums opened this issue May 16, 2024 · 0 comments · Fixed by #45
Closed

[EC88] Dispose resource asynchronously #44

Djoums opened this issue May 16, 2024 · 0 comments · Fixed by #45
Assignees
Labels
🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request

Comments

@Djoums
Copy link
Collaborator

Djoums commented May 16, 2024

Category : Usage

Severity : Warning

Why is this an issue ?

Asynchronous operations free up the main thread, allowing it to handle other tasks or enter an idle state, which can lead to lower CPU usage and power consumption. Efficient resource utilization minimizes the overall environmental footprint of applications by reducing the time resources are held, lowering server load, and improving scalability.

Therefore, resources that implement IAsyncDisposable should be disposed asynchronously whenever possible.

When can it be ignored ?

This rule shouldn't be ignored.

Examples

public static void Test()
{
    using var stream = new MemoryStream(); // Compliant, method is synchronous
}
public static async Task Test()
{
    using var stream = new MemoryStream(); // Non-compliant, can be disposed asynchronously
}
public static async Task Test()
{
    await using var stream = new MemoryStream(); // Compliant
}
@Djoums Djoums self-assigned this May 16, 2024
@Djoums Djoums added 🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗃️ rule rule improvment or rule development or bug 🚀 enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant