Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ProcessWatchImpl/Rusk/ProcessWatcher.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 43 by netseed, Thu Dec 10 14:18:56 2009 UTC revision 44 by netseed, Tue Dec 15 16:20:54 2009 UTC
# Line 21  namespace Toast.ProcessControl Line 21  namespace Toast.ProcessControl
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
# Line 75  namespace Toast.ProcessControl Line 75  namespace Toast.ProcessControl
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    
# Line 94  namespace Toast.ProcessControl Line 94  namespace Toast.ProcessControl
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    
# Line 127  namespace Toast.ProcessControl Line 127  namespace Toast.ProcessControl
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                          }                          }
# Line 137  namespace Toast.ProcessControl Line 137  namespace Toast.ProcessControl
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                          }                          }
# Line 150  namespace Toast.ProcessControl Line 150  namespace Toast.ProcessControl
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                  }                  }

Legend:
Removed from v.43  
changed lines
  Added in v.44

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26