Is Discards feature correctly works with IDisposable objects?
Is it call Dispose();
when its needed?
I have a code:
Boolean existing = Mutex.TryOpenExisting(name: key, rights: MutexRights.ReadPermissions, result: out Mutex _);
Here I need only existing
variable value.
As you see, I'm trying to use "discard" variable here, but I'm not sure this is correct usage in this case or not.
Because of Mutex obj implements IDisposable.
So which way will be correct in this case? this:
Boolean existing = Mutex.TryOpenExisting(name: key, rights: MutexRights.ReadPermissions, result: out Mutex _);
or this:
Mutex mutex;
Boolean existing = Mutex.TryOpenExisting(name: key, rights: MutexRights.ReadPermissions, result: mutex);
mutex.Dispose();
_.Dispose();
is not wrong, but reviewed behind the door on the right. – Mastaba_.Dispose();
code a little bit later, thanks :) – Flinger_
tomutex
. – Mastaba