cache problem for StreamReader

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I create a file, use StreamReader to read this file, the file content is
corrent,
i create this file again with different content, then read this file again,
the file content not change, it's seem cache by .Net or FileSystem.

can i solve this problem?
 
I create a file, use StreamReader to read this file, the file content
is corrent, i create this file again with different content, then
read this file again, the file content not change, it's seem cache by
.Net or FileSystem.

can i solve this problem?

Be sure, that you close or flush the stream-writer, that is writing the
file, otherwise the content may not be written then.
Additionally, be sure, that you are reading really the same file again.
To simple test it, make a breakpoint in the debugger after writing the
file, check the files content, then start over with reading the file...

Maybe you must re-create the reader at the second read - but I don't
know that yet, just give it a try, if the above suggestions do not work.

hth
Markus
 
Pony Tsui said:
I create a file, use StreamReader to read this file, the file content is
corrent,
i create this file again with different content, then read this file
again,
the file content not change, it's seem cache by .Net or FileSystem.


You'll make sure the data gets written to the file. To do so, call the
writer's 'Flush' method. In addition make sure you are using another
'StreamReader' object to read the file.
 
Hi Markus,

Thanks for your reply.

The file was create by cobol, so i can not flush it, i sure it read the same
file because if i read this file about one minites later after first read,
the content will be corrent!
 
The file was create by cobol, so i can not flush it, i sure it read
the same file because if i read this file about one minites later
after first read, the content will be corrent!

Then maybe it's your cobol-application, which does not flush the content
and close the file stream correctly... did you have a look at that?
Because your problem is, that your file is not immediately available for
a second read - therefore the problem must be somewhere in the write
process (as I assume from my knowledge of you application).

Markus
 
Hi Pony,

There's no cache for StreamReader. As Markus and Herfried said, you should
make it sure that the new content gets written to the file and use a new
StreamReader object to read the file.

Hope this helps.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Linda,

Thanks for your reply.

This is my code:

private sub readTestFile()

' call cobol program form to Create a file TEST.TXT
' call cobol program code here

Dim f As StreamReader = Nothing
Dim strAllLine As String = ""
Dim remoteFileName As String = "remoteServer:\folder\TEST.TXT"
Dim localFileName As String = "c:\TEST.TXT." & Format(Now, "HHmmssFF")
FileCopy(remoteFileName , localFileName)
Try
f = New StreamReader(localFileName, Encoding.GetEncoding(950))
Try
Do While f.Peek >= 0
strAllLine += Trim(f.ReadLine)
Loop
Catch ex As Exception
MsgBox("Read TEST.TXT Error: " & ex.Message)
Finally
f.Close()
Kill(localFileName)

' if add sleep(5000) i can get the new file content
' System.Threading.Thread.Sleep(5000)

End Try
msgbox(strAllLine)
end sub

any suggest?
 
Difficult to say from here, as you code even does not compile (missing
end try statement)... and what are you doing in Kill(localFileName)?

However, from the parts I am seeing here, the place where you add the
Thread.Sleep is not relevant, as the Sleep is AFTER reading the file. So
I suspect that you are changing the variable with the content
(strAllLine) in some parts of the code that is not shown here...

Markus
 
Hi Pony,

Thank you for prompt response.

Do you call the cobol program to create a file TEST.TXT on the remote
server and then copy it to a local file in the readTestFile method? Is the
call to the cobol program asynchronous?

I think you may set a break point right after the code of
"FileCopy(remoteFileName , localFileName)" to see if the new content is
copied to the local file.

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Linda,

Thanks for your reply.

My cobol program create a file and given the smae file name on a NAS server,
then i copy the file from NAS server to local disk given different name,
after i call the cobol program twice, the NAS file changed, but the second
local file not changed, so maybe it cache by NAS server or cache by the
windows file system,
the nas server do not have any configure of the cache, is there any way to
check the windows file system?

However, because the file created on a unix server, so i change the copy
mothed from filecopy to rcp, it's seem work fine.

Thanks Linda, and thanks Markus, you do help me!!
 
Hi Pony,
after i call the cobol program twice, the NAS file changed, but the
second local file not changed....

Could you tell me what you mean by "the NAS file changed, but the second
local file not changed"? Do you call the cobol program twice in the
readTestFile procedure? If yes, why do you do like that?
the nas server do not have any configure of the cache, is there any way
to check the windows file system?

Since you just copy the TEST.TXT file on the NAS server to your local
machine, I don't think the TEST.TXT file will be cached in your local
machine.
However, because the file created on a unix server, so i change the copy
mothed from filecopy to rcp, it's seem work fine.

Do you mean that after you change the copy method from filecopy to rcp, the
problem is resolved?

I look forward to your reply.


Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top