Added a few checks and delays to the driver loading code to increase the chance of loading the driver.

This commit is contained in:
Michael Möller
2012-08-11 21:48:54 +00:00
parent e32ce0060d
commit 5a8544454e
2 changed files with 22 additions and 3 deletions
+20 -1
View File
@@ -98,13 +98,29 @@ namespace OpenHardwareMonitor.Hardware {
try {
using (FileStream target = new FileStream(fileName, FileMode.Create)) {
target.Write(buffer, 0, buffer.Length);
target.Flush();
}
} catch (IOException) {
// for example there is not enough space on the disk
return false;
}
return true;
// make sure the file is actually writen to the file system
for (int i = 0; i < 20; i++) {
try {
if (File.Exists(fileName) &&
new FileInfo(fileName).Length == buffer.Length)
{
return true;
}
Thread.Sleep(100);
} catch (IOException) {
Thread.Sleep(10);
}
}
// file still has not the right size, something is wrong
return false;
}
public static void Open() {
@@ -141,6 +157,9 @@ namespace OpenHardwareMonitor.Hardware {
// install failed, try to delete and reinstall
driver.Delete();
// wait a short moment to give the OS a chance to remove the driver
Thread.Sleep(2000);
string errorSecondInstall;
if (driver.Install(fileName, out errorSecondInstall)) {
driver.Open();
+2 -2
View File
@@ -10,5 +10,5 @@
using System.Reflection;
[assembly: AssemblyVersion("0.5.1.1")]
[assembly: AssemblyInformationalVersion("0.5.1.1 Alpha")]
[assembly: AssemblyVersion("0.5.1.2")]
[assembly: AssemblyInformationalVersion("0.5.1.2 Alpha")]