-
October 28th, 2018, 05:13 PM
#16
Re: GetLastWriteTime
Originally Posted by Arjay
Can you explain (again) what happens to the file after the last change is detected and why it is important to work with a locked file?
It's conjecture that the file is copied, but the open, locked file is synced to another location immediately after a change is saved. Whether it was by VSS or not, I can't say. I don't have access to the program code of the program. I didn't notice any difference between the open file and the saved, sync file, if there was any integrity issue. I don't know if an integrity issue would evolve after multiple syncs, either.
I suppose it would work to sync a file after it has been released, it's just interesting that someone has done the sync work on the fly as changes are made. Whether that's advisable or not, I don't know. I just noticed that's it's being done. But wouldn't system notifications have to be ignored or otherwise dealt with as they pop up during the save process on locked files? That I don't know anything about. I also don't know anything about asynchronous processes, which is something else I'll have to deal with later, I think.
-
October 28th, 2018, 05:54 PM
#17
Re: GetLastWriteTime
My question is toward what you are trying to accomplish. You may have mentioned this in some other thread already.
-
October 29th, 2018, 03:06 PM
#18
Re: GetLastWriteTime
Originally Posted by Arjay
My question is toward what you are trying to accomplish. You may have mentioned this in some other thread already.
I think my objective is to create a backup utility that syncs between two folders on a pc in a timely manner. I suppose I'm comparing what I can create with other applications, but I'm learning what I want to produce as I find out what's possible. Overall, though, the primary objective is to provide that mens to backup information.
-
October 29th, 2018, 07:53 PM
#19
Re: GetLastWriteTime
Sounds like vss is the way to go.
-
October 29th, 2018, 10:04 PM
#20
Re: GetLastWriteTime
Originally Posted by Arjay
Sounds like vss is the way to go.
I have doubts about that after what you said about partial file info. I don't want to jeopardize file integrity by using a means like VSS if it leads to inferior process. Quality is preferable to expediency. I'd like to know anything you've got to tell me about this.
-
October 29th, 2018, 10:08 PM
#21
Re: GetLastWriteTime
Originally Posted by KGCole
I have doubts about that after what you said about partial file info. I don't want to jeopardize file integrity by using a means like VSS if it leads to inferior process. Quality is preferable to expediency. I'd like to know anything you've got to tell me about this.
I'm not sure I have anything left to add. Time to start coding and try out some different approaches.
-
November 6th, 2018, 12:05 AM
#22
Re: GetLastWriteTime
Originally Posted by Arjay
I'm not sure I have anything left to add. Time to start coding and try out some different approaches.
Sorry, had to be away from things for a while. On this subject, I put a method together to test whether the changed file is released, but I haven't been able to get the exception for the error ignored if it's still locked. The exception still interrupts the process and says the file is in an open process. So basically I don't know how to have the exception ignored. Here's the sub, don't know how I can change it to get the desired result:
Code:
Private Function VerifyLastWrite(e As FileSystemEventArgs) As Boolean
Dim fileDone As Boolean
Try
Dim fs As FileStream = New FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)
fileDone = True
Catch ex As Exception
fileDone = False
End Try
Return fileDone
-
November 7th, 2018, 07:58 AM
#23
Re: GetLastWriteTime
Originally Posted by KGCole
Sorry, had to be away from things for a while. On this subject, I put a method together to test whether the changed file is released, but I haven't been able to get the exception for the error ignored if it's still locked. The exception still interrupts the process and says the file is in an open process. So basically I don't know how to have the exception ignored. Here's the sub, don't know how I can change it to get the desired result:
Code:
Private Function VerifyLastWrite(e As FileSystemEventArgs) As Boolean
Dim fileDone As Boolean
Try
Dim fs As FileStream = New FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)
fileDone = True
Catch ex As Exception
fileDone = False
End Try
Return fileDone
You need to put the FileStream check inside a using block like it is in my example code. The using block will cause the FileStream to release the file object when it goes out of scope (which is immediately at the end of the using block). If you don't have a using block, the FileStream object you are using to check the file will itself keep a lock on the file.
From my code snippet:
Code:
try
{
using( FileStream fs = new FileStream( args.FullPath, FileMode.Open, FileAccess.Read, FileShare.None ) )
{
// Debug.WriteLine( args.FullPath );
transferCompleted = true;
} // IMPORTANT: the using block will release the FileStream object (and the lock for this object) here
} catch( IOException )
{
// Ignore exceptions where we can't open the file
// This is because the file is still being copied
}
Last edited by Arjay; November 7th, 2018 at 08:07 AM.
-
November 7th, 2018, 08:34 PM
#24
Re: GetLastWriteTime
Originally Posted by Arjay
You need to put the FileStream check inside a using block like it is in my example code. The using block will cause the FileStream to release the file object when it goes out of scope (which is immediately at the end of the using block). If you don't have a using block, the FileStream object you are using to check the file will itself keep a lock on the file.
I'm not sure I constructed this using statement correctly. My code still gets interrupted with the locked process error. Could you tell me what is wrong with this snippet?
Code:
Private Function VerifyLastWrite(e As FileSystemEventArgs) As Boolean
Dim fileDone As Boolean
Try
Using fs As FileStream = New FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.None)
fileDone = True
End Using
Catch ex As Exception
fileDone = False
End Try
Return fileDone
End Function
-
November 7th, 2018, 10:07 PM
#25
Re: GetLastWriteTime
What happens if you debug and step through the code?
-
November 7th, 2018, 11:14 PM
#26
Re: GetLastWriteTime
Originally Posted by Arjay
What happens if you debug and step through the code?
If I put a breakpoint on the using declaration and let it run to that point, then run the code through after the break, I don't get the error. Don't know quite what to make of that. If I don't have a breakpoint, I always get the error...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|