![]() |
![]() |
|
|||||||
| Register | Forum Rules | Getting Started! - Guide | Blog | Videos | Gallery | Members List | Social Groups | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#41 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem
OK, have you tried this.
Are you opening the file to read something or other? If so, are you closing the file after you are done? File.Open(<Filename>,Mode.Read) ' When done File.Close ' Optional, but good practice. Clears the component from the memory. File.Dispose It seems you are either not closing the file when you are accessing it from another thread. See if this helps. -- Ryan S. Thiele RT Enterprises The Power is in your hands now! |
|
|
|
#42 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem
"kimiraikkonen" <kimiraikkonen85@gmail.com> schrieb
> 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") I also use a StreamReader and a StreamWriter. I'm afraid, without seeing your code I am not able to help. Armin |
|
|
|
#43 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem
"kimiraikkonen" <kimiraikkonen85@gmail.com> schrieb
> 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") I also use a StreamReader and a StreamWriter. I'm afraid, without seeing your code I am not able to help. Armin |
|
|
|
#44 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem (OT)
On Dec 13, 8:10 pm, "Armin Zingler" <az.nos...@freenet.de> wrote:
> "kimiraikkonen" <kimiraikkone...@gmail.com> schrieb > > > 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 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! |
|
|
|
#45 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem
OK, have you tried this.
Are you opening the file to read something or other? If so, are you closing the file after you are done? File.Open(<Filename>,Mode.Read) ' When done File.Close ' Optional, but good practice. Clears the component from the memory. File.Dispose It seems you are either not closing the file when you are accessing it from another thread. See if this helps. -- Ryan S. Thiele RT Enterprises The Power is in your hands now! |
|
|
|
#46 |
|
Guest
Posts: n/a
|
Re: StreamWriter Problem
"kimiraikkonen" <kimiraikkonen85@gmail.com> schrieb
> 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") I also use a StreamReader and a StreamWriter. I'm afraid, without seeing your code I am not able to help. Armin |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |