473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Synchronized StreamWriter - Is Flush ThreadSafe?

Hi all,

I'm accessing a synchronized Streamwriter from potentially several threads
to do some logging. Is the Flush command threadsafe too? Should I single
thread the Flush command or will the Synchronized streamwriter handle that
for me?

Thanks!
Jun 6 '07 #1
5 5697

How are you writing to the log? I have public methods that are synclocked
on the log instance for writing in my class. You can also make the stream
auto-flush by default which is handy.
Jun 6 '07 #2
"Robin Tucker" <rt******@hotmail.comwrote in
news:f4*******************@news.demon.co.uk:
>
How are you writing to the log? I have public methods that are
synclocked on the log instance for writing in my class. You can also
make the stream auto-flush by default which is handy.
The Synchronized Stream doesn't seem to support Auto-Flush.

I'm not synclocking the StreamReader because I heard it is still "unsafe".
Rather I'm using the thread-safe synchronized wrapper.

So I like to know if the threadsafe wrapper wraps everything ... or just
..write.
Jun 6 '07 #3

No I mean you have a class that wraps the stream and synclock that, so
writers are never accessing the stream directly. It is privately
encapsulated. For example, instead of writing Debug.Writeline(), the coder
will use MyTracer.WriteLine (), where MyTracer is your accessor class that
does the synclock.
Jun 6 '07 #4
"Robin Tucker" <rt******@hotmail.comwrote in
news:f4*******************@news.demon.co.uk:
>
No I mean you have a class that wraps the stream and synclock that, so
writers are never accessing the stream directly. It is privately
encapsulated. For example, instead of writing Debug.Writeline(), the
coder will use MyTracer.WriteLine (), where MyTracer is your accessor
class that does the synclock.
I could do that - but the Synchronized Stream is SUPPOSED to be threadsafe.
So I'm just trying to confirm the fact about the .flush.

There's no sense in rewrapping a threadsafe class right?
Jun 6 '07 #5
"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Robin Tucker" <rt******@hotmail.comwrote in
news:f4*******************@news.demon.co.uk:
>>
No I mean you have a class that wraps the stream and synclock that, so
writers are never accessing the stream directly. It is privately
encapsulated. For example, instead of writing Debug.Writeline(), the
coder will use MyTracer.WriteLine (), where MyTracer is your accessor
class that does the synclock.

I could do that - but the Synchronized Stream is SUPPOSED to be
threadsafe.
So I'm just trying to confirm the fact about the .flush.

There's no sense in rewrapping a threadsafe class right?
Well that depends on what else you are doing with the stream. If it's nout,
then you should be fine with it.
Jun 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vladimir Bezugliy | last post by:
I have a server that listen a socket. And I have next client: TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000); NetworkStream networkStream = socketForServer.GetStream();...
1
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a...
3
by: José Joye | last post by:
I have 2 threads using the same StreamWriter (obtained from FileInfo.AppendText). This first thread will always use the WriteLine() method and the second thread will always use the Flush() method....
4
by: ASP Yaboh | last post by:
I am using StreamWriter's .Writeline() method to create a simple text file. I found that ASCII characters 255 & 254 are being inserted as the first two characters of the file which causes a...
1
by: andpapas | last post by:
In my multi-threaded application i'm getting to a point where I've got the exception bellow: ------------------------------------------------------------------------...
1
by: Max Powers | last post by:
Hello, I have a VB.NET code that creates a StreamWriter file first and then it does a series of procedures that write lines for this StreamWriter. When all the procedures are done, the...
4
by: Heron | last post by:
Hi, Could someone explain me why the following code doesn't work? The memorystream always remains with length 0. MemoryStream input = new MemoryStream();
7
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. I'm building an ASP.NET site which is hosted on a remote server. When I try to create a new file using StreamWriter I must specify the drive location where the file will be saved. I don't...
1
by: fniles | last post by:
If I use TextWriter synchronized method like below codes if another thread is trying to write at the same time, what will happen ? Will it the 2nd thread request to write to the file be queued ?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.