tagged [idisposable]
Why does Enumerable.Range Implement IDisposable?
Why does Enumerable.Range Implement IDisposable? Just wondering why `Enumerable.Range` implements `IDisposable`. I understand why `IEnumerator` does, but `IEnumerable` doesn't require it. --- (I disco...
- Modified
- 4 Jul at 03:39
What is the difference between using and await using? And how can I decide which one to use?
What is the difference between using and await using? And how can I decide which one to use? I've noticed that in some case, Visual Studio recommends to do this Instead of this What is the difference ...
- Modified
- 29 Apr at 11:28
Can I "inline" a variable if it's IDisposable?
Can I "inline" a variable if it's IDisposable? Do I have to do this to ensure the MemoryStream is disposed of properly? or is it OK to inline the MemoryStream so that it simply goes out of scope? Like...
- Modified
- 15 Dec at 04:34
using statement in C# 8 without a variable
using statement in C# 8 without a variable Is there a mechanism for the new c# 8 `using` statement to work without a local variable? Given `ScopeSomething()` returns a `IDisposable` (or `null`)... Pre...
- Modified
- 11 Apr at 02:13
Is IDisposable.Dispose() called automatically?
Is IDisposable.Dispose() called automatically? > [Will the Garbage Collector call IDisposable.Dispose for me?](https://stackoverflow.com/questions/45036/will-the-garbage-collector-call-idisposable-di...
- Modified
- 23 May at 12:26
How to use disposable view models in WPF?
How to use disposable view models in WPF? How do I ensure view models are properly disposed of if they reference unmanaged resources or have event handlers such as handling elapsed on a dispatcher tim...
- Modified
- 8 Aug at 14:40
Will Dispose() be called in a using statement with a null object?
Will Dispose() be called in a using statement with a null object? Is it safe to use the `using` statement on a (potentially) null object? Consider the following example: ``` class Test { IDisposable...
- Modified
- 20 Dec at 16:30
How to unit test a method with a `using` statement?
How to unit test a method with a `using` statement? How can I write a unit test for a method that has a using statement? For example let assume that I have a method `Foo`. How can I test something lik...
- Modified
- 23 Dec at 17:14
Why should Dispose() be non-virtual?
Why should Dispose() be non-virtual? I'm new to C#, so apologies if this is an obvious question. In the [MSDN Dispose example](http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx), the Dispose metho...
- Modified
- 1 Sep at 15:4
Is there a list of common object that implement IDisposable for the using statement?
Is there a list of common object that implement IDisposable for the using statement? I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... `SQLCon...
- Modified
- 23 Jun at 15:33
return the variable used for using inside the using C#
return the variable used for using inside the using C# I am returning the variable I am creating in a using statement inside the using statement (sounds funny): Will this Dispose the properties variab...
- Modified
- 12 May at 20:53
Create a temporary file from stream object in c#
Create a temporary file from stream object in c# Given a stream object which contains an xlsx file, I want to save it as a temporary file and delete it when not using the file anymore. I thought of cr...
- Modified
- 9 Mar at 17:32
Form.ShowDialog() and dispose
Form.ShowDialog() and dispose If I have a method like this: on the form even though it will go out of scope, which will be eligible for garbage collection. From some testing, calling this Show() multi...
- Modified
- 12 Jul at 14:39
How to dispose objects having asynchronous methods called?
How to dispose objects having asynchronous methods called? I have this object `PreloadClient` which implements `IDisposable`, I want to dispose it, but after the asynchronous methods finish their call...
- Modified
- 10 Jun at 11:10
Should Dispose() or Finalize() be used to delete temporary files?
Should Dispose() or Finalize() be used to delete temporary files? I have a class that makes use of temporary files (`Path.GetTempFileName()`) while it is active. I want to make sure these files do not...
- Modified
- 13 Jul at 19:59
Is there a way for a class that implements IDisposable to throw an exception if it's not been instantiated via a using block?
Is there a way for a class that implements IDisposable to throw an exception if it's not been instantiated via a using block? I spotted some potentially dangerous classes that would be much less dange...
- Modified
- 28 Oct at 22:29
Why CancellationTokenRegistration exists and why does it implement IDisposable
Why CancellationTokenRegistration exists and why does it implement IDisposable I've been seeing code that uses `Cancellation.Register` with a `using` clause on the `CancellationTokenRegistration` resu...
- Modified
- 4 May at 09:9
Questions about Entity Framework Context Lifetime
Questions about Entity Framework Context Lifetime I have some questions about the desired lifetime of an Entity Framework context in an ASP.NET MVC application. Isn't it best to keep the context alive...
- Modified
- 20 Apr at 16:21
Does foreach automatically call Dispose?
Does foreach automatically call Dispose? In C#, Does foreach automatically call Dispose on any object implementing IDisposable? [http://msdn.microsoft.com/en-us/library/aa664754(v=vs.71).aspx](http://...
- Modified
- 13 Feb at 04:23
How write several using instructions?
How write several using instructions? > [using statement with multiple variables](https://stackoverflow.com/questions/9396064/using-statement-with-multiple-variables) I have several disposable objec...
- Modified
- 23 May at 12:4
Am I implementing IDisposable correctly?
Am I implementing IDisposable correctly? This class uses a `StreamWriter` and therefore implements `IDisposable`. ``` public class Foo : IDisposable { private StreamWriter _Writer; public Foo (Str...
- Modified
- 8 May at 08:53
IDisposable GC.SuppressFinalize(this) location
IDisposable GC.SuppressFinalize(this) location I use a default IDisposable implementation template (pattern) for my code. snippet: ``` public void Dispose() { Dispose(true); GC.SuppressFinalize(th...
- Modified
- 12 Apr at 06:52
Is there any benefit to implementing IDisposable on classes which do not have resources?
Is there any benefit to implementing IDisposable on classes which do not have resources? In C#, if a class, such as a manager class, does not have resources, is there any benefit to having it `: IDisp...
- Modified
- 27 Feb at 21:7
Using a null IDisposable value with the using statement
Using a null IDisposable value with the using statement The following code produces no errors when executed: `using` If so, where is it documented? Most C# code I've seen will create a "dummy/NOP" IDi...
- Modified
- 24 Oct at 02:13
What's the purpose of GC.SuppressFinalize(this) in Dispose() method?
What's the purpose of GC.SuppressFinalize(this) in Dispose() method? I have the following code: ``` public void Dispose() { if (_instance != null) { _instance = null; // Call GC.SupressFin...
- Modified
- 29 May at 03:13