I am currently using filestreams to copy files from one place to another. All this worked as intended until now, when I suddenly had a problem that File.open was freezing the thread in which it was running.
FileStream sourceStream = File.Open(filePath, FileMode.Open)
This only happens for 1 specific file (3 GB in size). Interestingly, one day before it functioned normally, although the file size may not be the case for this file. The next thing I checked was that some kind of exception was made that I wonโt catch.
I put the try / catch block as a whole (usually I use the calling method to throw exceptions) and the same effect.
try { FileStream sourceStream = File.Open(filePath, FileMode.Open); sourceStream.Close(); } catch (Exception e) { Console.Write("A"); }
I also checked what happens if the file is already accessed. Then an exception is thrown (checked for other files, as I said for this particular file, it always hangs in the stream when I try to open it).
The file is located on the local hard drive, and other files (although smaller) in the same folder do not show this problem.
As I am now running out of ideas, what is the possible reason, my question is: What can be the reasons for this unexpected behavior and how can they be advertised?
EDIT: Now it functions again (only when I tried to use the process monitor did it start functioning again). Thus, in general, there is no reason whatsoever for this phenomenon. If anyone had an idea of โโwhat might be the possible cause of this, it would be good to know in order to avoid a possible recurrence of the problem in the future.
Also notice how one question brought it to the File.Open file. I have a using block:
using (var stream = new BufferedStream(File.OpenRead(filePath), 1024 * 1024)) {
What I use to create some hash calculations regarding a file. It had no problems at all with opening the file (only later File.Open had problems)
Edit: I just received information from system administrators who are shining a new light on the problem: The system is configured in such a way that the whole system will be archived from file from time to time if the OS did not know about it. This means that in the case of a backup file, which the OS believes that it exists, and no one accesses it, when in fact it is currently subject to backup (and thus access to it cannot be accessed from the inside OS in accordance with the description of the backup process ..... since the OS does not know about the origin of the backup, nothing was shown in accessing the resources of the hard disk or task manager). Thus, with this information it may happen that, since the OS does not know about the file it is accessing, it tried to access it (via the open command) and waited and waited and waited for the read header of the hard disk to go to the file which was never the same as in reality it was inaccessible). Thus, he would have to start a timeout that does not have the file.open command (at least my hunch is there with new information, if I understood the system administrators correctly)
Tnx