public void CancelWorker(int nId) { #region LOG { string message = @"CancelWorker: " + nId; Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } #endregion lock (objWorkersLock) { JobProxy job = null; if (_nWorkers.TryGetValue(nId, out job)) { try { job.Cancel(); } catch { //ignore } } } }
static void RegisterWorker(int nId, JobProxy job) { lock (objWorkersLock) { _nWorkers.Add(nId, job); } }
static void JobWorker(Object stateInfo) { int nId = 0; JobProxy jp = null; try { _JobsPool.WaitOne(); nId = (int)stateInfo; jp = new JobProxy(DownloadJobsDataAccessAgent) { Id = nId }; RegisterWorker(nId, jp); jp.Execute(); } catch (Exception e) { #region LOG { string message = @"Job Worker Failure (most likely a db connection issue): " + e.Message; Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined, DateTime.Now, LogType.Information, MessageDirection.None, message, null, null); } #endregion #if DEBUG System.Diagnostics.Trace.WriteLine(e.Message); System.Diagnostics.Debugger.Break(); //most likely a db connection issue #endif //since most errors here are caused by db provider, we cant update the job status //exception ignored } finally { UnRegisterWorker(nId); Interlocked.Decrement(ref _nTotalWorkerThreads); _JobsPool.Release(); } }