| 21 |
|
|
| 22 |
public ProcessWatcher() |
public ProcessWatcher() |
| 23 |
{ |
{ |
| 24 |
this.timer_ = new Timer(new TimerCallback(TimerMain)); |
timer_ = new Timer(new TimerCallback(TimerMain)); |
| 25 |
this.isRun_ = false; |
isRun_ = false; |
| 26 |
this.TargetProcessName = null; |
TargetProcessName = null; |
| 27 |
this.isTargetProcessRun_ = false; |
isTargetProcessRun_ = false; |
| 28 |
this.CheckCountThreshold = 0; |
CheckCountThreshold = 0; |
| 29 |
this.CheckCount_ = 0; |
CheckCount_ = 0; |
| 30 |
} |
} |
| 31 |
|
|
| 32 |
public string TargetProcessName |
public string TargetProcessName |
| 75 |
return false; |
return false; |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
this.TargetProcessName = processName; |
TargetProcessName = processName; |
| 79 |
|
|
| 80 |
this.isRun_ = true; |
isRun_ = true; |
| 81 |
this.isTargetProcessRun_ = false; |
isTargetProcessRun_ = false; |
| 82 |
this.CheckCountThreshold = checkCount; |
CheckCountThreshold = checkCount; |
| 83 |
this.Interval = interval; |
Interval = interval; |
| 84 |
|
|
| 85 |
this.timer_.Change(DefaultDelay, interval); |
timer_.Change(DefaultDelay, interval); |
| 86 |
|
|
| 87 |
} |
} |
| 88 |
|
|
| 94 |
{ |
{ |
| 95 |
lock (syncRoot_) |
lock (syncRoot_) |
| 96 |
{ |
{ |
| 97 |
this.timer_.Change(Timeout.Infinite, Timeout.Infinite); |
timer_.Change(Timeout.Infinite, Timeout.Infinite); |
| 98 |
|
|
| 99 |
diag::Process[] Ret= diag::Process.GetProcessesByName(this.TargetProcessName); |
diag::Process[] Ret= diag::Process.GetProcessesByName(TargetProcessName); |
| 100 |
|
|
| 101 |
if (Ret.Length != 0 && !isTargetProcessRun_) |
if (Ret.Length != 0 && !isTargetProcessRun_) |
| 102 |
{ |
{ |
| 103 |
this.OnDetectProcessStart(this, EventArgs.Empty); |
OnDetectProcessStart(this, EventArgs.Empty); |
| 104 |
this.isTargetProcessRun_ = true; |
isTargetProcessRun_ = true; |
| 105 |
} |
} |
| 106 |
else if (Ret.Length == 0 && isTargetProcessRun_) |
else if (Ret.Length == 0 && isTargetProcessRun_) |
| 107 |
{ |
{ |
| 108 |
dbg::TinyDebugWriter.WriteLine("CheckCouht:{0}", CheckCount_); |
dbg::TinyDebugWriter.WriteLine("CheckCouht:{0}", CheckCount_); |
| 109 |
if (++this.CheckCount_ >= this.CheckCountThreshold) |
if (++CheckCount_ >= CheckCountThreshold) |
| 110 |
{ |
{ |
| 111 |
this.OnDetectProcessTerminated(this, EventArgs.Empty); |
OnDetectProcessTerminated(this, EventArgs.Empty); |
| 112 |
this.isTargetProcessRun_ = false; |
isTargetProcessRun_ = false; |
| 113 |
this.CheckCount_ = 0; |
CheckCount_ = 0; |
| 114 |
} |
} |
| 115 |
} |
} |
| 116 |
else |
else |
| 117 |
{ |
{ |
| 118 |
this.CheckCount_ = 0; |
CheckCount_ = 0; |
| 119 |
} |
} |
| 120 |
|
|
| 121 |
|
|
| 122 |
this.timer_.Change(this.Interval, this.Interval); |
timer_.Change(Interval, Interval); |
| 123 |
} |
} |
| 124 |
} |
} |
| 125 |
|
|
| 127 |
{ |
{ |
| 128 |
dbg::TinyDebugWriter.WriteLine("Detect process start"); |
dbg::TinyDebugWriter.WriteLine("Detect process start"); |
| 129 |
|
|
| 130 |
if (this.DetectProcessStart != null) |
if (DetectProcessStart != null) |
| 131 |
{ |
{ |
| 132 |
DetectProcessStart(sender, e); |
DetectProcessStart(sender, e); |
| 133 |
} |
} |
| 137 |
{ |
{ |
| 138 |
dbg::TinyDebugWriter.WriteLine("Detect process terminate"); |
dbg::TinyDebugWriter.WriteLine("Detect process terminate"); |
| 139 |
|
|
| 140 |
if (this.DetectProcessTerminate != null) |
if (DetectProcessTerminate != null) |
| 141 |
{ |
{ |
| 142 |
DetectProcessTerminate(sender, e); |
DetectProcessTerminate(sender, e); |
| 143 |
} |
} |
| 150 |
lock (syncRoot_) |
lock (syncRoot_) |
| 151 |
{ |
{ |
| 152 |
timer_.Change(Timeout.Infinite, Timeout.Infinite); |
timer_.Change(Timeout.Infinite, Timeout.Infinite); |
| 153 |
this.DetectProcessTerminate = null; |
DetectProcessTerminate = null; |
| 154 |
this.DetectProcessStart = null; |
DetectProcessStart = null; |
| 155 |
timer_.Dispose(); |
timer_.Dispose(); |
| 156 |
} |
} |
| 157 |
} |
} |