diff --git a/Crystallography/Crystallography.csproj b/Crystallography/Crystallography.csproj index f50cc24..ace82ac 100644 --- a/Crystallography/Crystallography.csproj +++ b/Crystallography/Crystallography.csproj @@ -38,7 +38,7 @@ - + diff --git a/Crystallography/Miscellaneous.cs b/Crystallography/Miscellaneous.cs index bcd8c9d..920778b 100644 --- a/Crystallography/Miscellaneous.cs +++ b/Crystallography/Miscellaneous.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Drawing; +using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading; @@ -108,6 +109,53 @@ public static bool IsDecimalPointComma public static (int Division, int Modulus) DivMod(int n, int m) => (n / m, n % m); + /// + /// ファイルが使用中かどうかをチェック + /// + /// + /// + public static bool isFileExistsAndLocked(string path) + { + if (File.Exists(path)) + { + FileStream stream = null; + + try + { + stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); + } + catch (DirectoryNotFoundException e) + { + return false; + } + catch (FileNotFoundException e) + { + return false; + } + catch (IOException e) + { + if (File.Exists(path)) + { + return true; + } + } + catch (Exception e) + { + return false; + } + finally + { + if (stream != null) + { + stream.Close(); + } + } + + return false; + } + + return false; + } } diff --git a/IPAnalyzer/FormAutoProcedure.Designer.cs b/IPAnalyzer/FormAutoProcedure.Designer.cs index 1116207..d3f71b2 100644 --- a/IPAnalyzer/FormAutoProcedure.Designer.cs +++ b/IPAnalyzer/FormAutoProcedure.Designer.cs @@ -130,7 +130,6 @@ private void InitializeComponent() numericBoxDivisor.BackColor = System.Drawing.Color.Transparent; numericBoxDivisor.Name = "numericBoxDivisor"; numericBoxDivisor.RadianValue = 0.052359877559829883D; - numericBoxDivisor.RoundErrorAccuracy = -1; numericBoxDivisor.Value = 3D; // // radioButtonEqual @@ -153,7 +152,6 @@ private void InitializeComponent() numericBoxRemainder.BackColor = System.Drawing.Color.Transparent; numericBoxRemainder.Name = "numericBoxRemainder"; numericBoxRemainder.RadianValue = 0.034906585039886591D; - numericBoxRemainder.RoundErrorAccuracy = -1; numericBoxRemainder.Value = 2D; // // groupBox2 diff --git a/IPAnalyzer/FormAutoProcedure.cs b/IPAnalyzer/FormAutoProcedure.cs index a13707b..b488e2d 100644 --- a/IPAnalyzer/FormAutoProcedure.cs +++ b/IPAnalyzer/FormAutoProcedure.cs @@ -8,6 +8,7 @@ using Crystallography; using System.Text; using System.Collections.Generic; +using System.Threading; #endregion namespace IPAnalyzer; @@ -112,6 +113,9 @@ private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { if (!checkBoxPatternMatching.Checked) { + while (Miscellaneous.isFileExistsAndLocked(f)) + Thread.Sleep(50); + formMain.ReadImage(f); // break; } @@ -132,6 +136,12 @@ private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) if ((radioButtonEqual.Checked && num % numericBoxDivisor.ValueInteger == numericBoxRemainder.ValueInteger) || (radioButtonNotEqual.Checked && num % numericBoxDivisor.ValueInteger != numericBoxRemainder.ValueInteger)) { + long fileSize = 0; + while (fileSize != new FileInfo(f).Length) + { + Thread.Sleep(50); + fileSize = new FileInfo(f).Length; + } formMain.ReadImage(f); // break; } @@ -145,7 +155,7 @@ private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) } catch { System.Threading.Thread.Sleep(1000); } - System.Threading.Thread.Sleep(200); + System.Threading.Thread.Sleep(100); } } diff --git a/IPAnalyzer/FormAutoProcedure.ja.resx b/IPAnalyzer/FormAutoProcedure.ja.resx index 40c58b9..ea3ab9e 100644 --- a/IPAnalyzer/FormAutoProcedure.ja.resx +++ b/IPAnalyzer/FormAutoProcedure.ja.resx @@ -1,7 +1,7 @@