Synchronized TextWriters - change / reopen !?

A

andpapas

In my multi-threaded application i'm getting to a point where I've got
the exception bellow:

------------------------------------------------------------------------
System.ObjectDisposedException: Cannot write to a closed TextWriter.
Server stack trace:
at System.IO.__Error.WriterClosed()
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean
flushEncoder)
at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32
count)
at System.IO.TextWriter.WriteLine(String value)
at RemoteObject.DebugLogger.ExceptionLog(String aLogMessage)
at RemoteObject.DataAccessObject.ExecuteSQL(String aFuncName,
ArrayList aParameterList, DataSet& aDataset)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(MethodBase
mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage
msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at RemoteObject.DataAccessObject.ExecuteSQL(String aFuncName,
ArrayList aParameterList, DataSet& aDataset)
at RemoteClient.DataAccessClient.funct_name(Int32 comArrSize, Byte[]
i_appl_id, IntPtr*& o_icgdd_1v_r, IntPtr& no_of_rows_returned)
--------------------------------------------------------------------------

PS: I've used a TextWriter wrapper for StreamWriter class in order to
use the synchronization.

Thanks,
Papas
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Well according to the exception the stream is closed , did you close it
previously?

post the code you are using otherwise.


cheers,
 
A

andpapas

I have a logger class which is used by two different application: one
writting into a common file, the other one using the same logger object
to write to multiple files.
So, i had to sync the writers by declaring them as static. However, the
second application sometimes closes the filestream, and such, the
static textwriter object is closed.
My problem is: how to check that the static textwriter object is closed
and how to reopen it!
Thanks
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Are you using two different applications?
if so you have two different instances of the logger, the static is bounded
to the appdomain, not to the system.

What if you do this, create a third app , a Logger app. This is the only
application that does the logging, the other two ( or any other number ) of
apps just use IPC to access the logging app. In this way you have the
flexibility to change the logging logic, device, etc at will, as long as you
do not change the interface you do not need to change the consumers ( apps
using the logger )

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top