Skip to content

Commit 7cb74d7

Browse files
committed
fine tunning
1 parent 1af5c0a commit 7cb74d7

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

ServiceSpooler/Processors/Monitor.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ public void Start() {
7878

7979
if (! cancellation.IsCancellationRequested) {
8080

81-
ProcessOrphans(null, null);
82-
8381
monitorTimer = new System.Timers.Timer(monitorInterval * 1000);
8482
monitorTimer.Elapsed += ProcessOrphans;
85-
monitorTimer.Start();
83+
84+
ProcessOrphans(null, null);
8685

8786
}
8887

@@ -157,11 +156,10 @@ private void ProcessOrphans(object sender, EventArgs args) {
157156

158157
log.Trace("Entering ProcessOrphans()");
159158

160-
cancellation = new CancellationTokenSource();
161-
162-
ConnectionEvent.Wait(cancellation.Token);
159+
try {
163160

164-
if (! cancellation.IsCancellationRequested) {
161+
monitorTimer.Stop();
162+
ConnectionEvent.Wait(cancellation.Token);
165163

166164
foreach (Watcher watcher in DirectoryWatchers.Values) {
167165

@@ -175,6 +173,16 @@ private void ProcessOrphans(object sender, EventArgs args) {
175173

176174
tasks.Clear();
177175

176+
monitorTimer.Start();
177+
178+
} catch (OperationCanceledException) {
179+
180+
log.Debug("ProcessOrphans() - Ignored an OperationCanceledException");
181+
182+
} catch (Exception ex) {
183+
184+
log.Debug(String.Format("ProcessOrphans() - Ignored an Exception: {0}", ex));
185+
178186
}
179187

180188
log.Trace("Leaving ProcessOrphans()");
@@ -191,20 +199,25 @@ private void EnqueueOrphans(Watcher watcher) {
191199
log.Trace("Entering EnqueueOrphans()");
192200
log.Debug(String.Format("EnqueueOrphans() - processing {0}", watcher.directory));
193201

194-
var files = watcher.spool.Scan();
202+
try {
195203

196-
log.Debug(String.Format("EnqueueOrphans() - found {0} files in {1}", files.Count(), watcher.directory));
204+
var files = watcher.spool.Scan();
197205

198-
foreach (string file in files) {
206+
log.Debug(String.Format("EnqueueOrphans() - found {0} files in {1}", files.Count(), watcher.directory));
199207

200-
if (cancellation.IsCancellationRequested) {
208+
foreach (string file in files) {
201209

202-
log.Debug("EnqueueOrphans() - cancellation requested");
203-
break;
210+
OnEnqueuePacket(file);
204211

205212
}
206213

207-
OnEnqueuePacket(file);
214+
} catch (OperationCanceledException) {
215+
216+
log.Debug("EnqueueOrphans() - Ignored an OperationCanceledException");
217+
218+
} catch (Exception ex) {
219+
220+
log.Debug(String.Format("EnqueueOrphans() - Ignored an Exception: {0}", ex));
208221

209222
}
210223

0 commit comments

Comments
 (0)