I am having a very strange problem with StreamWriter and writing to files.
I have a procedure that is called several times to write out seperate files,
each of them uniquely named by date all they way to the one hundred
thousandth of a second. After the data is encrypted and written, the
StreamWriter is closed and the function is returned. This all works fine
and dandy, except when it is called more than once in succession.
Originally, the file append flag in the StreamWriter constructor was
accidentally left to true and I was getting some files where there was two
files worth of data in them. After turning the append flag off, I am
usually short one or two files because it can't append.
I have solved the problem temporarily by putting a Thread.Sleep(100) in
before creating the new StreamWriter object, but with the volume of file
writing that will be occuring when this goes public, it will cause too much
of a slow down. Is there a way to safely write data to a file, close it and
ensure that the next file write isnt going to step on the current one?
Thank you for any help you can provide.
Bob Hansen 2 2161
Bob Hansen <bh********@jascorp.com> wrote: I am having a very strange problem with StreamWriter and writing to files. I have a procedure that is called several times to write out seperate files, each of them uniquely named by date all they way to the one hundred thousandth of a second. After the data is encrypted and written, the StreamWriter is closed and the function is returned. This all works fine and dandy, except when it is called more than once in succession. Originally, the file append flag in the StreamWriter constructor was accidentally left to true and I was getting some files where there was two files worth of data in them. After turning the append flag off, I am usually short one or two files because it can't append.
I have solved the problem temporarily by putting a Thread.Sleep(100) in before creating the new StreamWriter object, but with the volume of file writing that will be occuring when this goes public, it will cause too much of a slow down. Is there a way to safely write data to a file, close it and ensure that the next file write isnt going to step on the current one?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Bob Hansen <bh********@jascorp.com> wrote: I am having a very strange problem with StreamWriter and writing to files. I have a procedure that is called several times to write out seperate files, each of them uniquely named by date all they way to the one hundred thousandth of a second. After the data is encrypted and written, the StreamWriter is closed and the function is returned. This all works fine and dandy, except when it is called more than once in succession. Originally, the file append flag in the StreamWriter constructor was accidentally left to true and I was getting some files where there was two files worth of data in them. After turning the append flag off, I am usually short one or two files because it can't append.
I have solved the problem temporarily by putting a Thread.Sleep(100) in before creating the new StreamWriter object, but with the volume of file writing that will be occuring when this goes public, it will cause too much of a slow down. Is there a way to safely write data to a file, close it and ensure that the next file write isnt going to step on the current one?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
by: James |
last post by:
Hi,
I am new to .NET framework. I am trying to get data from the third
party web application using WebHTTPRequest and Response class. I am
getting TimeOut exception at GetResponse Method..
...
|
by: Bob Hansen |
last post by:
I am having a very strange problem with StreamWriter and writing to files.
I have a procedure that is called several times to write out seperate files,
each of them uniquely named by date all they...
|
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...
|
by: W Akthar |
last post by:
Hi
I am trying to create a windows service which queries SQL
Server on timed intervals and depending on the results
send appointments to Outlook.
The problem lies when I try to create an...
| |
by: R.L. |
last post by:
See the code below, var 'content ' is suppose to be "Hello!", not "". Who
knows why? Thanks
----------------------------------------
string text = "hello!";
MemoryStream stream = new...
|
by: Bruce Wiebe |
last post by:
hi all
im having a problem accessing a text file on my hard disk after ive
created it and added some text to it it would appear that the file is
still locked.
What happens is this i have...
|
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();
|
by: asem0525 |
last post by:
Hello guys, I have this kind of problem:
first, the textBox tbISBN has a value that is read from the text file, but then after pressing the "Clear" button, it should be realized, and when I enter...
|
by: kengtung |
last post by:
Greetings all,
I just started programming with C# (.Net FW 1.1) last year and still
learning. Previously I am using VB 6.0.
Recently, in one application, I encountered a C# error "Cannot write...
|
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,...
| |
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: 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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |