mohammad
mohammad

Reputation: 1318

If I have a Dispose method, must I implement IDisposable?

I have a class that contains a Dispose method. In this method I abort a thread. Is it necessary to implement the IDisposable interface?

Upvotes: 4

Views: 114

Answers (1)

Adil
Adil

Reputation: 148120

If you implement IDisposable interface then your class object could be used in using block that automatically call the Dispose method implicitly.

From the answer from JaredPar

There are only 2 reasons for implementing IDisposable on a type

  • The type contains native resources which must be freed when the type is no longer used
  • The type contains fields of type IDisposable

Is there any benefit to implementing IDisposable on classes which do not have resources?

Upvotes: 1

Related Questions