public virtual void RequestSynchronization() { base.ExecuteMethod("RequestSynchronization", delegate() { INotifySynchronizer notifySync = this.IFoundation.SafeResolve <INotifySynchronizer>(); if (notifySync != null) { notifySync.SyncEntity(this.EntityName); } }); }
protected virtual void AttemptExecuteWithinTimeout(bool waitForRefreshInterval, int customMillisecondTimeout, string methodName, Action action) { base.ExecuteMethod(methodName, delegate() { if (customMillisecondTimeout <= 0) { // run in new task, we dont wanna wait Task.Run(action); return; } try { using (CancellationTokenSource tokenSource = new CancellationTokenSource()) { CancellationToken token = tokenSource.Token; Task task = Task.Run(action, token); tokenSource.CancelAfter(customMillisecondTimeout); task.Wait(token); token.ThrowIfCancellationRequested(); if (waitForRefreshInterval) { Task.Delay(MILLISECONDS_FOR_REFRESH).Wait(); } } } catch (OperationCanceledException cex) { HealthReporter.Current.UpdateMetric(HealthTrackType.Each, string.Format(HealthReporter.INDEXER_INSTANT_FAIL_TIMEOUT_FORMAT, this.EntityName), 0, 1); this.IFoundation.LogError(cex, "AttemptExecuteWithinTimeout:" + methodName); INotifySynchronizer notifySync = this.IFoundation.SafeResolve <INotifySynchronizer>(); if (notifySync != null) { notifySync.OnSyncFailed(this.EntityName, ""); } } catch (Exception ex) { HealthReporter.Current.UpdateMetric(HealthTrackType.Each, string.Format(HealthReporter.INDEXER_INSTANT_FAIL_ERROR_FORMAT, this.EntityName), 0, 1); this.IFoundation.LogError(ex, "AttemptExecuteWithinTimeout:" + methodName); INotifySynchronizer notifySync = this.IFoundation.SafeResolve <INotifySynchronizer>(); if (notifySync != null) { notifySync.OnSyncFailed(this.EntityName, ""); } } }); }