?
=?ISO-8859-1?Q?=22D=2E_Andr=E9_Dhondt=22?=
How do I dispose of a shared object instance only once--after all
consumers of it have been disposed of?
More detail:
I have a VB.NET trace class that I invoke as a shared instance in the
business code I'm interested in logging. The trace class needs to close
out of the file when I'm done using the business objects--but since many
objects may be using it, I don't want to close the trace file before
everyone has had a chance to use it.
for example:
'----------.dll/server-side component
Public Class business_class
Implements IDisposable
Shared log_trace as New Trace_class
Public Sub SampleMethod()
Trace.WriteLine("starting SampleMethod")
'...
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
log_trace.Dispose
End Sub
End Class
'----------client-side component
Public Sub Main()
Dim my_business as Business_class
Dim your_business as Business_class
my_business.SampleMethod
your_business.SampleMethod
my_business.Dispose() 'the problem here is that it shouldn't yet call
log_trace.Dispose
my_business = Nothing
your_business.Dispose()
your_business = Nothing
End Sub
consumers of it have been disposed of?
More detail:
I have a VB.NET trace class that I invoke as a shared instance in the
business code I'm interested in logging. The trace class needs to close
out of the file when I'm done using the business objects--but since many
objects may be using it, I don't want to close the trace file before
everyone has had a chance to use it.
for example:
'----------.dll/server-side component
Public Class business_class
Implements IDisposable
Shared log_trace as New Trace_class
Public Sub SampleMethod()
Trace.WriteLine("starting SampleMethod")
'...
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
log_trace.Dispose
End Sub
End Class
'----------client-side component
Public Sub Main()
Dim my_business as Business_class
Dim your_business as Business_class
my_business.SampleMethod
your_business.SampleMethod
my_business.Dispose() 'the problem here is that it shouldn't yet call
log_trace.Dispose
my_business = Nothing
your_business.Dispose()
your_business = Nothing
End Sub