mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-06-03 08:34:04 +02:00
Fix LockManager to check process name before reporting, and cleanup Close/Dispose code
Closes #17
This commit is contained in:
parent
4cef0fb60d
commit
016e403309
@ -54,7 +54,15 @@ public bool Lock(){
|
|||||||
int pid = BitConverter.ToInt32(bytes,0);
|
int pid = BitConverter.ToInt32(bytes,0);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
lockingProcess = Process.GetProcessById(pid);
|
Process foundProcess = Process.GetProcessById(pid);
|
||||||
|
|
||||||
|
using(Process currentProcess = Process.GetCurrentProcess()){
|
||||||
|
if (foundProcess.ProcessName == currentProcess.ProcessName){
|
||||||
|
lockingProcess = foundProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentProcess.Close();
|
||||||
|
}
|
||||||
}catch(ArgumentException){}
|
}catch(ArgumentException){}
|
||||||
|
|
||||||
return lockingProcess == null && CreateLockFile();
|
return lockingProcess == null && CreateLockFile();
|
||||||
@ -76,7 +84,6 @@ public bool Lock(){
|
|||||||
|
|
||||||
public void Unlock(){
|
public void Unlock(){
|
||||||
if (lockStream != null){
|
if (lockStream != null){
|
||||||
lockStream.Close();
|
|
||||||
lockStream.Dispose();
|
lockStream.Dispose();
|
||||||
File.Delete(file);
|
File.Delete(file);
|
||||||
|
|
||||||
@ -96,7 +103,7 @@ public bool CloseLockingProcess(int timeout){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lockingProcess.HasExited){
|
if (lockingProcess.HasExited){
|
||||||
lockingProcess.Close();
|
lockingProcess.Dispose();
|
||||||
lockingProcess = null;
|
lockingProcess = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user