@@ -78,11 +78,10 @@ public void Start() {
78
78
79
79
if ( ! cancellation . IsCancellationRequested ) {
80
80
81
- ProcessOrphans ( null , null ) ;
82
-
83
81
monitorTimer = new System . Timers . Timer ( monitorInterval * 1000 ) ;
84
82
monitorTimer . Elapsed += ProcessOrphans ;
85
- monitorTimer . Start ( ) ;
83
+
84
+ ProcessOrphans ( null , null ) ;
86
85
87
86
}
88
87
@@ -157,11 +156,10 @@ private void ProcessOrphans(object sender, EventArgs args) {
157
156
158
157
log . Trace ( "Entering ProcessOrphans()" ) ;
159
158
160
- cancellation = new CancellationTokenSource ( ) ;
161
-
162
- ConnectionEvent . Wait ( cancellation . Token ) ;
159
+ try {
163
160
164
- if ( ! cancellation . IsCancellationRequested ) {
161
+ monitorTimer . Stop ( ) ;
162
+ ConnectionEvent . Wait ( cancellation . Token ) ;
165
163
166
164
foreach ( Watcher watcher in DirectoryWatchers . Values ) {
167
165
@@ -175,6 +173,16 @@ private void ProcessOrphans(object sender, EventArgs args) {
175
173
176
174
tasks . Clear ( ) ;
177
175
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
+
178
186
}
179
187
180
188
log . Trace ( "Leaving ProcessOrphans()" ) ;
@@ -191,20 +199,25 @@ private void EnqueueOrphans(Watcher watcher) {
191
199
log . Trace ( "Entering EnqueueOrphans()" ) ;
192
200
log . Debug ( String . Format ( "EnqueueOrphans() - processing {0}" , watcher . directory ) ) ;
193
201
194
- var files = watcher . spool . Scan ( ) ;
202
+ try {
195
203
196
- log . Debug ( String . Format ( "EnqueueOrphans() - found {0} files in {1}" , files . Count ( ) , watcher . directory ) ) ;
204
+ var files = watcher . spool . Scan ( ) ;
197
205
198
- foreach ( string file in files ) {
206
+ log . Debug ( String . Format ( "EnqueueOrphans() - found {0} files in {1}" , files . Count ( ) , watcher . directory ) ) ;
199
207
200
- if ( cancellation . IsCancellationRequested ) {
208
+ foreach ( string file in files ) {
201
209
202
- log . Debug ( "EnqueueOrphans() - cancellation requested" ) ;
203
- break ;
210
+ OnEnqueuePacket ( file ) ;
204
211
205
212
}
206
213
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 ) ) ;
208
221
209
222
}
210
223
0 commit comments