473,386 Members | 1,754 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,386 software developers and data experts.

StreamWriter and Multi-threading

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.
At the present, I have protected the access to the StreamWriter using a
Lock() section.

Is this really particular case, is this necessary?
What could be the implication if I remove the Lock() section?

Thanks,
José
Nov 15 '05 #1
3 4987
While one sw is writing to the file, the other one is flushing the buffer?
What are you trying to achieve here?

regards,
Peter
"Jos?Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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.
At the present, I have protected the access to the StreamWriter using a
Lock() section.

Is this really particular case, is this necessary?
What could be the implication if I remove the Lock() section?

Thanks,
Jos?

Nov 15 '05 #2
In fact the client using my class needs to write information in a file.
However, it has really little time at disposal (I can not flush information
synchrously, it will take too much time). Therefore, the method called by
the client will make a writeline (which does not flush and therefore it is
quick) it will send set an event for an async. thread telling some info
needs to be flush.

Hope this sounds clear?

Do you have an answer to my question?
José
"Peter Q" <pm****@cogeco.ca> a écrit dans le message de
news:Hr*******************@read1.cgocable.net...
While one sw is writing to the file, the other one is flushing the buffer?
What are you trying to achieve here?

regards,
Peter
"Jos?Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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.
At the present, I have protected the access to the StreamWriter using a
Lock() section.

Is this really particular case, is this necessary?
What could be the implication if I remove the Lock() section?

Thanks,
Jos?


Nov 15 '05 #3
In fact the client using my class needs to write information in a file.
However, it has really little time at disposal (I can not flush information
synchrously, it will take too much time). Therefore, the method called by
the client will make a writeline (which does not flush and therefore it is
quick) it will send set an event for an async. thread telling some info
needs to be flush.

Hope this sounds clear?

Do you have an answer to my question?
José
"Peter Q" <pm****@cogeco.ca> a écrit dans le message de
news:Hr*******************@read1.cgocable.net...
While one sw is writing to the file, the other one is flushing the buffer?
What are you trying to achieve here?

regards,
Peter
"Jos?Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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.
At the present, I have protected the access to the StreamWriter using a
Lock() section.

Is this really particular case, is this necessary?
What could be the implication if I remove the Lock() section?

Thanks,
Jos?


Nov 15 '05 #4

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();...
4
by: Majed | last post by:
Hi , all I'm trying to write unicode to a file for another app (not developed with vs2003) to read it. I used StreamWriter with unicode encoding.but I was surprised that the streamwriter adds FFFE...
1
by: Daniel | last post by:
i would like to konw when the data sent so that i can close the streamwriter and networkstream is there some sort of call backs/events i have to implement for this to work? if so how? can i just...
3
by: stax | last post by:
Hello, can somebody tell me how to serialize/deserialize a object containing a multi line string using the XmlSerializer class. One of the both windows linefeed chars get dumped somewhere down...
9
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the...
4
by: rex64 | last post by:
I am getting an error message and I have not been able to figure hot how to fix it. I have done some research with no answers yet. I found this code that may help? Not sure what to do with it....
10
by: Oscar Thornell | last post by:
Hi, I generate and temporary saves a text file to disk. Later I upload this file to Microsoft MapPoint (not so important). The file needs to be in UTF-8 encoding and I explicitly use the...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
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();
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.