Reputation: 3434
I have code similar to the following, should I explicity dispose of the listener object in the following code?
i.e should this code:
foreach (System.Diagnostics.TraceListener listener in localObj.Listeners)
listener.WriteLine("some logging");
be re-written as:
foreach (System.Diagnostics.TraceListener listener in localObj.Listeners)
{
listener.WriteLine("some logging");
listener.Dispose();
}
reasons for either way of coding would be appreciated.
Upvotes: 0
Views: 298
Reputation: 645
Sorry, I would like to comment on the ChrisBint answers, but I couldn't. In brief, I agree with ChrisBint, you should not call Dispose in the above-mentioned scenario:
Upvotes: 1
Reputation: 12904
In the above code, you are just accessing a reference to each TraceListener
and calling the WriteLine()
Method and there is no need to call Dispose()
in this scenario.
Upvotes: 3