I open the file with read access and allowing subsequent read | write | remove access to the file sharing file (file tail). If the file is deleted during processing, is there a way to detect that the file is awaiting deletion (see Section " http://msdn.microsoft.com/en-us/library/aa363858(v=VS.85).aspx )? If any Either an external process (ownership process) issued a deletion, I want to close my descriptor as soon as possible in order to allow deletion of the file so as not to interfere with any logic in the ownership process.
I am in C # and do not see a method for detecting pending deletion. A file was opened using a FileStream object. Is there a way to detect deletion in C # or in some other Windows features?
I would use a different signaling mechanism. (I make the assumption that access to the file is under your control, and not from a closed external program, mainly because of the flags used.)
The only "solution" within these boundaries that I can think of is a file access poll and an exception check (if any) that you return. Perhaps something is much more complex (at a lower level than the win32 API file?!?), But this is already following the path of "uhg" :-)
FileSystemWatcher, , , "" ; IS , FileSystemWatcher , , . ( ), , , FileStream , , .
- , FileInfo . FileInfos , , . NotifyFilter , . , OnDeleted. , , , - -, , FileStream. ; , , . , , .
, , . , , , FileSystemWatcher (FSW) . , FSW :
FileSystemWatcher
private bool _fileExists = true; public void Process(string pathToOriginalFile, string pathToCopy) { File.Copy(pathToOriginalFile, pathToCopy); FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = pathToOriginalFile; watcher.Deleted += new FileSystemEventHandler(OnFileDeleted); bool doneProcessing = false; watcher.EnableRaisingEvents = true; while(_fileExists && !doneProcessing) { // process the copy here } ... } private void OnFileDeleted(object source, FileSystemEventArgs e) { _fileExists = false; }
, . , / , oplocks . , , ( , API- .., ).
Source: https://habr.com/ru/post/1763640/More articles:How to set a USB camera as a source for wpf MediaElemt in VS2010 in C #? - visual-studio-2010Background Color DataGridViewCheckboxCell - c #AVFoundation Camera preview screen gives incorrect zoom - iphoneapopos / find contextual information - pythonC # Access Method Redirection - objectНе удается подключиться к Oracle DB с Java - ORA-12560: TNS: ошибка адаптера протокола - javaIs WCF Chunking Ready to Use? - wcfError compiling newlib - armHow to set the area / rectangle in which the cursor is allowed to move? - c ++Is it possible to use jQuery to select elements from the returned html string? - jqueryAll Articles