StreamWriter Problem

K

kimiraikkonen

OK. I didn't try that tool myself so I don't know if it works or not. Maybe
you find another tool similar to this which works better. That kind of tool
might be the only way to find out what happens.

Is there any difference between running with debugger or only the
executable? Could it be possible that debugger won't release the file
sometimes and keeps it locked? Or does it matter how often you try to save
the file?

-Teemu

No, using with debugger or seperate executable makes no difference.
 
T

Teemu

"kimiraikkonen" <[email protected]> kirjoitti viestissä

No, using with debugger or seperate executable makes no difference.

The last thing I can imagine is that antivirus software checks that file
sometimes and that causes this strange behavior. Or is your loading function
working properly? Does it close all streams?

I tried to loop your code 1000 times twice and no exceptions occurred.

-Teemu
 
F

Family Tree Mike

kimiraikkonen said:
If you're asking my posts, none of them was sent twice, but if you see
total message number higher than actual messages before clicking on
thread, that's because i needed to remove and re-post the message due
to need of modiying, not message duplication.

No, I am seeing duplicates.
 
K

kimiraikkonen

The last thing I can imagine is that antivirus software checks that file
sometimes and that causes this strange behavior. Or is your loading function
working properly? Does it close all streams?

I tried to loop your code 1000 times twice and no exceptions occurred.

-Teemu

Antivirus is disabled when trying this. However, this happens very
rarely, even sometimes i have to do this for hundres of times to
reproduce the problem, and only happens with overwritten files(very
rare) with that streamwriter code:

If Save.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Try
myStreamWriter =
System.IO.File.CreateText(Save.FileName)
myStreamWriter.Write(TextBox1.Text)
myStreamWriter.Flush()
myStreamWriter.Close()
myStreamWriter.Dispose()
Catch ex As Exception
msgbox(ex.message)
End If

Finally
If Not myStreamWriter Is Nothing Then
myStreamWriter.Close()

End If

End Try

Anyway. I'd better test the codes for a while which author's
recommended. Thanks all.
 
K

kimiraikkonen

No, I am seeing duplicates.

No, I'm accessing group under Google website and there's no duplicated
messages sent by me, beleive it.
Anyway, the group posting system a bit problematic that i can't
understand why i'm forced to remove and re-post a message instead of
editing/modifiying with one click like on modern forum systems like
PhpBB.

When you remove and -re-post a message for the purpose of modifiying,
total number of messages seems more than actual messages on the board.

If there would be a "edit" funtion provided to the poster, there
wasn't such a message mess or misunderstanding, BTW i know there's no
place to complain about it.
 
F

Family Tree Mike

kimiraikkonen said:
Antivirus is disabled when trying this. However, this happens very
rarely, even sometimes i have to do this for hundres of times to
reproduce the problem, and only happens with overwritten files(very
rare) with that streamwriter code:

If Save.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Try
myStreamWriter =
System.IO.File.CreateText(Save.FileName)
myStreamWriter.Write(TextBox1.Text)
myStreamWriter.Flush()
myStreamWriter.Close()
myStreamWriter.Dispose()
Catch ex As Exception
msgbox(ex.message)
End If

Finally
If Not myStreamWriter Is Nothing Then
myStreamWriter.Close()

End If

End Try

Anyway. I'd better test the codes for a while which author's
recommended. Thanks all.

I'm curious whether you see the same problem using

myStreamWriter = new StreamWriter(Save.FileName, false)
 
A

Armin Zingler

kimiraikkonen said:
No, I'm accessing group under Google website and there's no
duplicated messages sent by me, beleive it.

I also see your messages multiple times:
http://freenet-homepage.de/armin.zingler/posts.PNG

:)
Anyway, the group posting system a bit problematic that i can't
understand why i'm forced to remove and re-post a message instead of
editing/modifiying with one click like on modern forum systems like
PhpBB.
[...]

Welcome to the usenet! :) That's how it works. Once the message is sent, it
will be mirrored on many mirror servers all around the world. It is not a
single server or one provider that lets you edit a message.

You should better edit your message and review it until you think it's ready
to be sent. Get a reasonable newsreader for this. Outlook Express is not
bad. Maybe Thunderbird. There are others.

(BTW, you can't edit mails after sending them, too, can you? News articles
are very similar)


Armin
 
K

kimiraikkonen

OK, forget that problem, even it doesn't occur everytime with the
latest fixes, now there's bigger one:

I noticed newly: If i open large text files such as contains hundreds
of lines, i cannot edit / type textbox. Keyboard actions take no
effect, it behaves as if keyboard is locked. No key typing action
works. Also copy-paste doesn't work.

This problem does not occur for reasonable-sized files which have less
than 50 lines.

What is the solution for this? Could you try to reproduce same thing?
Open a large (very large) text file then try to edit it, try to enter
some words. I couldn't.

Thanks.
 
K

kimiraikkonen

No, I'm accessing group under Google website and there's no
duplicated messages sent by me, beleive it.

I also see your messages multiple times:http://freenet-homepage.de/armin.zingler/posts.PNG

:)
Anyway, the group posting system a bit problematic that i can't
understand why i'm forced to remove and re-post a message instead of
editing/modifiying with one click like on modern forum systems like
PhpBB.
[...]

Welcome to the usenet! :) That's how it works. Once the message is sent, it
will be mirrored on many mirror servers all around the world. It is not a
single server or one provider that lets you edit a message.

You should better edit your message and review it until you think it's ready
to be sent. Get a reasonable newsreader for this. Outlook Express is not
bad. Maybe Thunderbird. There are others.

(BTW, you can't edit mails after sending them, too, can you? News articles
are very similar)

Armin

Armin :) Thanks for teaching how Usenet works. But i'm sorry that i
don't see the same posting order from web-access through Google
groups.The update mechanism is different maybe. Also time stamps are
different than yours. Plus, when you call it as duplýcate or double-
post, the content must be "exacty" 1:1 copy / same. There may be
someconsecutive posts due to need of modifying because of not having
chance to edit, as you stated in your previous post. Anyway that
discussion is off-topic as you appreciate. Thanks.
 
F

Family Tree Mike

kimiraikkonen said:
OK, forget that problem, even it doesn't occur everytime with the
latest fixes, now there's bigger one:

I noticed newly: If i open large text files such as contains hundreds
of lines, i cannot edit / type textbox. Keyboard actions take no
effect, it behaves as if keyboard is locked. No key typing action
works. Also copy-paste doesn't work.

This problem does not occur for reasonable-sized files which have less
than 50 lines.

What is the solution for this? Could you try to reproduce same thing?
Open a large (very large) text file then try to edit it, try to enter
some words. I couldn't.

Thanks.

I think this is now a new issue that is not with StreamWriter, agreed?

I think it best then to start a new thread/post. The original thread is now
at 29 messages (at least where I view it, MSDN). I think it is time to start
fress with a new description briefly as to what you mean. For example, do
you mean you put the contents of the file into some control in your app, and
in that app you cannot edit it? If so, is it a TextBox (Multiline?), a
RichTextBox, or a custom control?
 
K

kimiraikkonen

I think this is now a new issue that is not with StreamWriter, agreed?

StreamWriter issue occurs sometimes, mycode is not different than
shown on the group board, but i need to work with streamwriter/reader
for hundreds of times to re-encounter the problem. If there wasn't a
bug in streamwriter or reader class, why this issue happens sometimes.
However, consider this, if you test the program for 100 times facing
with no problem then you say program is OK, but when you see the issue
on 101st try, you get confused. That's why it needs to be tried
harder.
I think it best then to start a new thread/post. The original thread is now
at 29 messages (at least where I view it, MSDN). I think it is time to start
fress with a new description briefly as to what you mean. For example, do
you mean you put the contents of the file into some control in your app, and
in that app you cannot edit it? If so, is it a TextBox (Multiline?), a
RichTextBox, or a custom control?

It's standard textbox control, no word processor. And multiline
enabled of course. But when i open small files with streamreader no
problem, but if i open larg (hundres of lines) text files, keyboard
gets locked and only backspace button works. You cannor enter letters
words, but normal or small size text files works great.
 
A

Armin Zingler

kimiraikkonen said:
Armin :) Thanks for teaching how Usenet works.

Didn't want to be insulting. Sorry, if it felt this way. Just wanted to show
that Jack is no singular case. Though, I still recommend a newsreader for
being able to edit posts til you want to send them.
Plus, when you call it as duplicate or double-
post, the content must be "exacty" 1:1 copy / same.
There may be
someconsecutive posts due to need of modifying because of not having
chance to edit, as you stated in your previous post.

Due to some of these cases from you, clarifying it one time should be
allowed.

It's not common use to post the work-in-progress versions. When can we know
when then final version arrives? So, it's also hard for the reader to handle
your different posts. "Duplicate" may have been the wrong word, but I
think you get the point. In the end, you can not blame the usenet for not
being able to edit posts because it's still your responsibilty not to send
before it's ready. Of course that happens to everyone somewhere along the
way, but as you see in my screenshot, it's confusing for the reader if it's
almost with every post. If it's by accident, no problem. If it's because you
didn't know that you can't edit afterwards, you should know it now and next
time only post the final versions.
Anyway that discussion is off-topic as you appreciate. Thanks.

Not really because you are posting right here.


Armin
 
K

kimiraikkonen

Didn't want to be insulting. Sorry, if it felt this way. Just wanted to show
that Jack is no singular case. Though, I still recommend a newsreader for
being able to edit posts til you want to send them.

No problem, it's OK.
Due to some of these cases from you, clarifying it one time should be
allowed.

It's not common use to post the work-in-progress versions. When can we know
when then final version arrives? So, it's also hard for the reader to handle
your different posts. "Duplicate" may have been the wrong word, but I
think you get the point. In the end, you can not blame the usenet for not
being able to edit posts because it's still your responsibilty not to send
before it's ready. Of course that happens to everyone somewhere along the
way, but as you see in my screenshot, it's confusing for the reader if it's
almost with every post. If it's by accident, no problem. If it's because you
didn't know that you can't edit afterwards, you should know it now and next
time only post the final versions.

No, i don't blame Usenet, it's the largest community since arch
ages :) Just i explained the reason why the posts were seen as double-
posted. (just for editing purpose), Even when you look at the content
of the "duplicated-called" posts, you'll see that i pay attention that
none of my posts' contents are the "exact" same.
Not really because you are posting right here.

Forget it, now i want to find the solution why i cannot edit (insert
and type some letters,words) with large text files after opening with
streamreader class. I'd better find the solution for this instead of
discussing amount of posts.

For example save this file as text (txt) then open it into a textbox
using mystreamreader, then click somewhere on the textbox the insert
some new words / to edit, you cannot edit. Keyboard typings take no
action.

Thanks.
 
K

kimiraikkonen

Didn't want to be insulting. Sorry, if it felt this way. Just wanted to show
that Jack is no singular case. Though, I still recommend a newsreader for
being able to edit posts til you want to send them.

No problem, it's OK.

- Hide quoted text -
- Show quoted text -
Due to some of these cases from you, clarifying it one time should be
allowed.
It's not common use to post the work-in-progress versions. When can we know
when then final version arrives? So, it's also hard for the reader to handle
your different posts. "Duplicate" may have been the wrong word, but I
think you get the point. In the end, you can not blame the usenet for not
being able to edit posts because it's still your responsibilty not to send
before it's ready. Of course that happens to everyone somewhere along the
way, but as you see in my screenshot, it's confusing for the reader if it's
almost with every post. If it's by accident, no problem. If it's because you
didn't know that you can't edit afterwards, you should know it now and next
time only post the final versions.

No, i don't blame Usenet, it's the largest community since arch
ages :) Just i explained the reason why the posts were seen as
double-
posted. (just for editing purpose), Even when you look at the content
of the "duplicated-called" posts, you'll see that i pay attention that
none of my posts' contents are the "exact" same.
Not really because you are posting right here.
Armin

Forget it, now i want to find the solution why i cannot edit (insert
and type some letters,words) with large text files after opening with
streamreader class. I'd better find the solution for this instead of
discussing amount of posts.

For example save this file as text (txt) then open it into a textbox
using mystreamreader, then click somewhere on the textbox the insert
some new words / to edit, you cannot edit. Keyboard typings take no
action.

Save this as text and open with streamreader class, try to enter new
letters. Keyboard gets locked. (for example):
http://www.ietf.org/rfc/rfc2475.txt


Thanks.
 
T

Teemu

kimiraikkonen said:
Forget it, now i want to find the solution why i cannot edit (insert
and type some letters,words) with large text files after opening with
streamreader class. I'd better find the solution for this instead of
discussing amount of posts.

For example save this file as text (txt) then open it into a textbox
using mystreamreader, then click somewhere on the textbox the insert
some new words / to edit, you cannot edit. Keyboard typings take no
action.

Save this as text and open with streamreader class, try to enter new
letters. Keyboard gets locked. (for example):
http://www.ietf.org/rfc/rfc2475.txt

The reason is Textbox1.Maxlength which default property is 32767. Change
that value and it should work as you wish.

-Teemu
 
K

kimiraikkonen

The reason is Textbox1.Maxlength which default property is 32767. Change
that value and it should work as you wish.

-Teemu

Great! Thanks! But which property refers to no limit?

Thanks again.
 
K

kimiraikkonen

Hi again,
I've tried all of code recommendations such as adding "close" and
"dispose" to stream writer and reader, the "this file is bein g used
by another process" problem occurs if you save and overwrite existing
file too fast after opening it. For example, consider that you opened
a text file with stream reader with no problem, then if you try to
save (overwrite) it in 1-2 seconds you get this error. Still i don't
know if there's no bug in streamwriter for overwriting existing files,
although i tried all of close, dispose , if nothing combinations, why
i got this notification.
 
A

Armin Zingler

kimiraikkonen said:
Hi again,
I've tried all of code recommendations such as adding "close" and
"dispose" to stream writer and reader, the "this file is bein g used
by another process" problem occurs if you save and overwrite
existing file too fast after opening it. For example, consider that
you opened a text file with stream reader with no problem, then if
you try to save (overwrite) it in 1-2 seconds you get this error.
Still i don't know if there's no bug in streamwriter for overwriting
existing files, although i tried all of close, dispose , if nothing
combinations, why i got this notification.

Can you try this in a new empty project? (change the path in the first line
before)

Public Class Form1
Const Path As String = "g:\test.bin"

Friend WithEvents Button1 As System.Windows.Forms.Button

Private Sub Form1_Load( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load

Me.Button1 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.Text = "Button1"

Me.Controls.Add(Button1)

End Sub

Shared Sub WriteFile()
Dim fs As New IO.FileStream(Path, IO.FileMode.Create)
Dim sw As New IO.StreamWriter(fs)
sw.WriteLine("bla")
sw.Dispose()
fs.Close()
End Sub
Shared Sub ReadFile()
Dim fs As New IO.FileStream(Path, IO.FileMode.OpenOrCreate)
Dim sr As New IO.StreamReader(fs)
sr.ReadLine()
sr.Dispose()
fs.Close()
End Sub
Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

Dim sw As New Stopwatch
Dim count As Integer
sw.Start()
Do
If Rnd() > 0.5 Then
ReadFile()
Else
WriteFile()
End If
count += 1
Loop Until sw.Elapsed.TotalSeconds > 60
MsgBox(count.ToString("#,###"))
End Sub

End Class


I don't get an error even though files are closed/opened/read/written about
200,000 times a minute.

Do you get an error?


Armin
 
K

kimiraikkonen

Can you try this in a new empty project? (change the path in the first line
before)

Public Class Form1
Const Path As String = "g:\test.bin"

Friend WithEvents Button1 As System.Windows.Forms.Button

Private Sub Form1_Load( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load

Me.Button1 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(12, 12)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.Text = "Button1"

Me.Controls.Add(Button1)

End Sub

Shared Sub WriteFile()
Dim fs As New IO.FileStream(Path, IO.FileMode.Create)
Dim sw As New IO.StreamWriter(fs)
sw.WriteLine("bla")
sw.Dispose()
fs.Close()
End Sub
Shared Sub ReadFile()
Dim fs As New IO.FileStream(Path, IO.FileMode.OpenOrCreate)
Dim sr As New IO.StreamReader(fs)
sr.ReadLine()
sr.Dispose()
fs.Close()
End Sub
Private Sub Button1_Click( _
ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click

Dim sw As New Stopwatch
Dim count As Integer
sw.Start()
Do
If Rnd() > 0.5 Then
ReadFile()
Else
WriteFile()
End If
count += 1
Loop Until sw.Elapsed.TotalSeconds > 60
MsgBox(count.ToString("#,###"))
End Sub

End Class

I don't get an error even though files are closed/opened/read/written about
200,000 times a minute.

Do you get an error?

Armin

Tried it with my old P4 2.ghz cpu, counted about 61-65000(your cpu is
4 times better i think :) ), however that code is a loop, automation,
good but my project wasn't like that, it was similiar to Notepad.
However i think you used first dispose and close classes, i did the
same but i got "file is being used" error frequently while closing the
form (added event to save on form.closing) and sometimes without
closing (working) with file.

However in my project i was using:
Dim myStreamWriter as System.IO.Streamwriter
myStreamWriter = System.IO.File.CreateText to write file with
streamwriter class.

and

Dim myStreamReader as System.IO.StreamReader
myStreamReader = System.IO.File.OpenText to open file with
streamreader class.


But you sampled it as:

System.IO.FileStream(Path, IO.FileMode.OpenOrCreate) instead of
System.IO.Streamreader

and

System.IO.FileStream(Path, IO.FileMode.Create) instead of
System.IO.StreamWriter

Yours classes are different, so i must ask that does that differ about
encountering problem(file is being used problem)?(difference between
"system.io.filestream" and "system.io.streamwriter/reader")

Thanks!
 

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