Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Got a report of some software getting stuck in a loop. I am using ReadAllText to read in a value, and WriteAllText to write a value separately (in different functions). The reported loop behaviour has me a little lost. can ReadAllText and WriteAllText get them selves in a knot that would cause this behaviour?
Posted

1 solution

Not if it's a single threaded app - it is sort-of possible in a multithreaded app, but even then The WriteAllText method acquires an Exclusive Lock from the file system before it starts writing and releases it when it's finished - if a different thread is reading at the time, the exclusive lock will fail and the WriteAllText will throw an exception. Similarly, if a different thread is Writing, then it will have an Exclusive lock, so the ReadAllText attempt to open the file for reading will fail, and it will throw an IOException.

I can't think of a circumstance where this would loop, unless you hda try-catch blocks around the read and write which loop until the file is available and there is something very odd in you code for that.

Is there any sign of corruption in the file?
 
Share this answer
 
Comments
glennPattonWork3 5-Jun-14 11:35am    
You have all the info I have (I think) translated to English from User English (over the pond not very techie). I don't have the file all I have is the stuff I sent, that works fine here!
OriginalGriff 5-Jun-14 11:46am    
That's always a pain: does the user elaborate on what "looping" means? Any error messages, odd displays, any idea what they were doing when it happened? How did they notice a problem?

In extreme cases write it up as a feature and issue a new version of the manual... :laugh:
OriginalGriff 5-Jun-14 11:47am    
Out of interest, can you remote in to their computer?
glennPattonWork3 5-Jun-14 11:54am    
No, besides the test set up this software is to be used on has no network connection (for security, you would think they were doing high sensitive work!). I have been working on this with both arms and a leg tied behind head! One thing is agreed then ignored and now this. I can't contact the person trying to test my software and he(or she! sorry must be PC) can't contact me. My Boss just wants to be cc'ed why can't the end customer be as reasonable?
glennPattonWork3 5-Jun-14 12:01pm    
I am doing this right:
System.IO.File.WriteAllText("FailedSerialNumber.ini", SerialNumberFailWrite, Encoding.UTF8)
it seems so odd that some thing like this crops up now!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900