0

I am refactoring a program right now. Trying to prevent memory leaks I was looking for objects to enclose in using blocks when I found a TaskDefinition object (class found in Microsoft.Win32.TaskScheduler) that Dispose was not called on. When I tried to enclose it VisualStudio told me that this class does not implement IDisosable. Looking at the class this is certainly true:

namespace Microsoft.Win32.TaskScheduler
{
    // Summary:
    //     Defines all the components of a task, such as the task settings, triggers,
    //     actions, and registration information.
    public sealed class TaskDefinition
    {
        ...

        // Summary:
        //     Releases all resources used by this class.
        public void Dispose();
    }
}

So why would you implement a Dispose method but not implement the IDisposable interface? Are there any drawbacks from implementing the interface?

Thank you for helping me to understand this.

5
  • Which dll this class lives in? Commented Sep 10, 2013 at 7:30
  • @SriramSakthivel Assembly Microsoft.Win32.TaskScheduler.dll, v1.7.4378.16959 Commented Sep 10, 2013 at 7:30
  • 2
    This is this one, right? If so, taskscheduler.codeplex.com/workitem/10612 lists it as a bug fixed in version 1.9.2. Commented Sep 10, 2013 at 7:34
  • I have the version 1.9.4 where it does implements IDisposable may be in earlier version they'd have forgotten Commented Sep 10, 2013 at 7:35
  • @hvd Could be that one. I took over the program from another developer so I am not sure but this seems like it is as the code is nearly exactly as the demo code on the main page of the project. Ok then post it as an answer and I will accept it. Commented Sep 10, 2013 at 7:40

1 Answer 1

3

From the comments:

According to this page, this is a bug that's fixed in newer versions of the assembly.

An additional note, however: the documentation for IDisposable.Dispose explicitly requires implementations to support calling Dispose multiple times, so a valid reason in other cases could be that the class does not support that. In that case, pretending to implement IDisposable but not meeting its requirements would be worse than not implementing it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.