[chronojump] Added IsFileLocked check to processes like webcam record
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added IsFileLocked check to processes like webcam record
- Date: Fri, 8 Feb 2019 14:59:24 +0000 (UTC)
commit 279ccb55d21f74fb20804dab32b0523c5776a3dd
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Feb 8 15:48:04 2019 +0100
Added IsFileLocked check to processes like webcam record
src/executeProcess.cs | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
---
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index d051bf1c..6d690e1c 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -325,6 +325,30 @@ class ExecuteProcess
}
*/
+ public static bool IsFileLocked(FileInfo finfo)
+ {
+ //https://stackoverflow.com/a/937558
+ FileStream stream = null;
+
+ try {
+ stream = finfo.Open(FileMode.Open, FileAccess.Read, FileShare.None);
+ }
+ catch (IOException) {
+ //the file is unavailable because it is:
+ //still being written to
+ //or being processed by another thread
+ //or does not exist (has already been processed)
+ return true;
+ }
+ finally {
+ if (stream != null)
+ stream.Close();
+ }
+
+ //file is not locked
+ return false;
+ }
+
/*
* The process.Responding only works on GUI processes
* So, here we send a "ping" expecting to see the result in short time
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]