Here are the examples of the csharp api System.Threading.Timer.Dispose() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
902 Examples
19
Source : Edi.cs
with MIT License
from 0ffffffffh
with MIT License
from 0ffffffffh
public static bool KillEdi()
{
if (ediSvc == null)
return true;
ediSvc.WipeClientInfos();
wipeTimer.Dispose();
wipeTimer = null;
ediSvc.Close();
ediSvc = null;
return true;
}
19
Source : Lock.cs
with MIT License
from 2881099
with MIT License
from 2881099
public bool Refresh(int milliseconds)
{
var ret = _client.Eval(@"local gva = redis.call('GET', KEYS[1])
if gva == ARGV[1] then
redis.call('PEXPIRE', KEYS[1], ARGV[2])
return 1
end
return 0", new[] { _name }, _value, milliseconds)?.ToString() == "1";
if (ret == false) _autoDelayTimer?.Dispose(); //未知情况,关闭定时器
return ret;
}
19
Source : PubSub.cs
with MIT License
from 2881099
with MIT License
from 2881099
internal IDisposable Subscribe(bool psub, string[] channels, Action<string, string, object> handler)
{
if (_stoped) return new PubSubSubscribeDisposable(this, null);
channels = channels?.Distinct().Where(a => !string.IsNullOrEmpty(a)).ToArray(); //In case of external modification
if (channels?.Any() != true) return new PubSubSubscribeDisposable(this, null);
var id = Guid.NewGuid();
var time = DateTime.Now;
var regkeys = channels.Select(a => psub ? $"{_psub_regkey_prefix}{a}" : a).ToArray();
for (var a = 0; a < regkeys.Length; a++)
{
ConcurrentDictionary<Guid, RegisterInfo> dict = null;
lock (_lock) dict = _registers.GetOrAdd(regkeys[a], k1 => new ConcurrentDictionary<Guid, RegisterInfo>());
dict.TryAdd(id, new RegisterInfo(id, handler, time));
}
lock (_lock)
_cancels.TryAdd(id, regkeys);
var isnew = false;
if (IsSubscribed == false)
{
lock (_lock)
{
if (IsSubscribed == false)
{
_redisSocket = _topOwner.Adapter.GetRedisSocket(null);
IsSubscribed = isnew = true;
}
}
}
if (isnew)
{
new Thread(() =>
{
_redisSocketReceiveTimeoutOld = _redisSocket.ReceiveTimeout;
_redisSocket.ReceiveTimeout = TimeSpan.Zero;
var timer = new Timer(state =>
{
_topOwner.Adapter.Refersh(_redisSocket); //防止 IdleBus 超时回收
try { _redisSocket.Write("PING"); } catch { }
}, null, 10000, 10000);
var readCmd = "PubSubRead".SubCommand(null).FlagReadbytes(false);
while (_stoped == false)
{
RedisResult rt = null;
try
{
rt = _redisSocket.Read(readCmd);
}
catch
{
Thread.CurrentThread.Join(100);
if (_cancels.Any()) continue;
break;
}
var val = rt.Value as object[];
if (val == null) continue; //special case
var val1 = val[0].ConvertTo<string>();
switch (val1)
{
case "pong":
case "punsubscribe":
case "unsubscribe":
continue;
case "pmessage":
OnData(val[1].ConvertTo<string>(), val[2].ConvertTo<string>(), val[3]);
continue;
case "message":
OnData(null, val[1].ConvertTo<string>(), val[2]);
continue;
}
}
timer.Dispose();
lock (_lock)
{
IsSubscribed = false;
_redisSocket.ReceiveTimeout = _redisSocketReceiveTimeoutOld;
_redisSocket.ReleaseSocket();
_redisSocket.Dispose();
_redisSocket = null;
}
}).Start();
}
Call((psub ? "PSUBSCRIBE" : "SUBSCRIBE").Input(channels));
return new PubSubSubscribeDisposable(this, () => Cancel(id));
}
19
Source : Lock.cs
with MIT License
from 2881099
with MIT License
from 2881099
public bool Delay(int milliseconds)
{
var ret = _client.Eval(@"local gva = redis.call('GET', KEYS[1])
if gva == ARGV[1] then
local ttlva = redis.call('PTTL', KEYS[1])
redis.call('PEXPIRE', KEYS[1], ARGV[2] + ttlva)
return 1
end
return 0", new[] { _name }, _value, milliseconds)?.ToString() == "1";
if (ret == false) _autoDelayTimer?.Dispose(); //未知情况,关闭定时器
return ret;
}
19
Source : Lock.cs
with MIT License
from 2881099
with MIT License
from 2881099
public bool Unlock()
{
_autoDelayTimer?.Dispose();
return _client.Eval(@"local gva = redis.call('GET', KEYS[1])
if gva == ARGV[1] then
redis.call('DEL', KEYS[1])
return 1
end
return 0", new[] { _name }, _value)?.ToString() == "1";
}
19
Source : BingAuthorization.cs
with MIT License
from adrenak
with MIT License
from adrenak
public void Dispose() {
StopFetch();
if (m_TokenTimer != null) m_TokenTimer.Dispose();
}
19
Source : BingAuthorization.cs
with MIT License
from adrenak
with MIT License
from adrenak
void CreateTimer() {
if (m_TokenTimer != null)
m_TokenTimer.Dispose();
m_TokenTimer = new Timer(
new TimerCallback(OnTokenExpiredCallback),
this,
TimeSpan.FromMinutes(k_RenewTimerDuration),
TimeSpan.FromMilliseconds(-1)
);
}
19
Source : ThreadedAsyncOperation.cs
with GNU General Public License v2.0
from afrantzis
with GNU General Public License v2.0
from afrantzis
public void OperationThread()
{
ActivateProgressReport(activateProgress);
try {
DoOperation();
if (cancelled)
opResult = OperationResult.Cancelled;
else
opResult = OperationResult.Finished;
}
catch (Exception e) {
threadException = e;
opResult = OperationResult.CaughtException;
}
finally {
progressTimer.Dispose();
showProgressTimer.Dispose();
EndOperation();
if (useGLibIdle)
GLib.Idle.Add(delegate { OperationFinished(); return false; });
else
OperationFinished();
}
}
19
Source : CatalogInvalidator.cs
with MIT License
from ai-traders
with MIT License
from ai-traders
public void Dispose()
{
if (_scanTimer != null)
_scanTimer.Dispose();
}
19
Source : TimedCleaner.cs
with MIT License
from AiursoftWeb
with MIT License
from AiursoftWeb
public void Dispose()
{
_timer?.Dispose();
}
19
Source : TimedCleaner.cs
with MIT License
from AiursoftWeb
with MIT License
from AiursoftWeb
public void Dispose() => _timer?.Dispose();
19
Source : ProgressBar.cs
with MIT License
from alecgn
with MIT License
from alecgn
public void Dispose()
{
lock (timer)
{
disposed = true;
UpdateText(string.Empty);
timer.Dispose();
}
}
19
Source : GroupContentsControlViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
void IDisposable.Dispose()
{
this.RetryTimer?.Dispose();
try
{
foreach (var msg in this.AllMessages.Items)
{
(msg as IDisposable)?.Dispose();
}
}
catch (Exception)
{
}
this.AllMessages.Clear();
}
19
Source : ChatsViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
private async Task LoadGroupsAndChats(bool updateSuperIndexer = false)
{
await this.ReloadGroupsSem.WaitAsync();
var persistContext = this.PersistManager.OpenNewContext();
try
{
await this.GroupMeClient.GetGroupsAsync();
await this.GroupMeClient.GetChatsAsync();
var groupsAndChats = Enumerable.Concat<IMessageContainer>(this.GroupMeClient.Groups(), this.GroupMeClient.Chats());
if (updateSuperIndexer)
{
// Submit new Group and Chat listings to SuperIndexer to allow for background indexing if needed.
this.CacheManager.SuperIndexer.BeginAsyncTransaction(groupsAndChats);
}
foreach (var group in groupsAndChats)
{
// check the last-read message status from peristant storage
var groupState = persistContext.GroupChatStates.FirstOrDefault(g => g.GroupOrChatId == group.Id);
if (groupState == null)
{
groupState = new GroupOrChatState()
{
GroupOrChatId = group.Id,
LastTotalMessageCount = group.TotalMessageCount,
};
persistContext.GroupChatStates.Add(groupState);
}
// Code to update the UI needs to be run on the Application Dispatcher
// This is typically the case, but Timer events from ReliabilityStateMachine for
// retry-callbacks will NOT run on the original thread.
var uiDispatcher = Ioc.Default.GetService<IUserInterfaceDispatchService>();
await uiDispatcher.InvokeAsync(() =>
{
// calculate how many new messages have been added since the group/chat was last read
var unreadMessages = group.TotalMessageCount - groupState.LastTotalMessageCount;
if (unreadMessages < 0)
{
// strange errors can occur when the Group Listing lags behind the
// actual group contents. If this occurs, cancel and reload the sidebar.
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(() => Task.Run(() => this.LoadGroupsAndChats()));
return;
}
var existingVm = this.AllGroupsChats.Items.FirstOrDefault(g => g.Id == group.Id);
if (existingVm == null)
{
// create a new GroupControl ViewModel for this Group
var vm = new GroupControlViewModel(group)
{
GroupSelected = new RelayCommand<GroupControlViewModel>((g) => this.OpenNewGroupChat(g)),
TotalUnreadCount = unreadMessages,
};
this.AllGroupsChats.Add(vm);
}
else
{
// Update the existing Group/Chat VM
existingVm.MessageContainer = group;
existingVm.TotalUnreadCount = unreadMessages;
}
var openChatGroup = this.AllChats.FirstOrDefault(g => g.Id == group.Id);
if (openChatGroup != null)
{
// chat is open and already receiving new messages, so mark all messages as "read"
existingVm.TotalUnreadCount = 0;
groupState.LastTotalMessageCount = openChatGroup.MessageContainer.TotalMessageCount;
}
});
}
await persistContext.SaveChangesAsync();
this.PublishTotalUnreadCount();
// if everything was successful, reset the reliability monitor
this.ReliabilityStateMachine.Succeeded();
this.RetryTimer?.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Exception in {nameof(this.LoadGroupsAndChats)} - {ex.Message}. Retrying...");
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(() => Task.Run(() => this.LoadGroupsAndChats()));
}
finally
{
persistContext.Dispose();
this.ReloadGroupsSem.Release();
}
}
19
Source : GroupContentsControlViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
private async Task LoadMoreAsync(bool updateNewest)
{
await this.ReloadSem.WaitAsync();
try
{
ICollection<Message> results;
if (this.FirstDisplayedMessage == null || updateNewest)
{
// load the most recent messages
results = await this.MessageContainer.GetMessagesAsync();
this.CacheManager.SuperIndexer.SubmitGroupUpdate(this.MessageContainer, results);
}
else
{
// load the 20 (GroupMe default) messages preceeding the oldest (first) one displayed
results = await this.MessageContainer.GetMessagesAsync(GroupMeClientApi.MessageRetreiveMode.BeforeId, this.FirstDisplayedMessage.Id);
}
await this.UpdateDisplay(results);
// if everything was successful, reset the reliability monitor
this.ReliabilityStateMachine.Succeeded();
this.RetryTimer?.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Exception in {nameof(this.LoadMoreAsync)} - {ex.Message}. Retrying...");
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(async () => await this.LoadMoreAsync(updateNewest));
}
finally
{
this.ReloadSem.Release();
}
}
19
Source : GroupContentsControlViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
void IDisposable.Dispose()
{
this.Messages.Clear();
this.RetryTimer?.Dispose();
try
{
foreach (var msg in this.Messages.Items)
{
(msg as IDisposable)?.Dispose();
}
}
catch (Exception)
{
}
}
19
Source : GroupContentsControlViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
private async Task LoadMoreAsync(ScrollViewer scrollViewer = null, bool updateNewest = false)
{
await this.ReloadSem.WaitAsync();
try
{
ICollection<Message> results;
if (this.FirstDisplayedMessage == null || updateNewest)
{
// load the most recent messages
results = await this.MessageContainer.GetMessagesAsync();
}
else
{
// load the 20 (GroupMe default) messages preceeding the oldest (first) one displayed
results = await this.MessageContainer.GetMessagesAsync(GroupMeClientApi.MessageRetreiveMode.BeforeId, this.FirstDisplayedMessage.Id);
}
this.UpdateDisplay(scrollViewer, results);
// if everything was successful, reset the reliability monitor
this.ReliabilityStateMachine.Succeeded();
this.RetryTimer?.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Exception in {nameof(this.LoadMoreAsync)} - {ex.Message}. Retrying...");
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(async () => await this.LoadMoreAsync(scrollViewer, updateNewest));
}
finally
{
this.ReloadSem.Release();
}
}
19
Source : ChatsViewModel.cs
with GNU General Public License v3.0
from alexdillon
with GNU General Public License v3.0
from alexdillon
private async Task LoadGroupsAndChats()
{
await this.ReloadGroupsSem.WaitAsync();
try
{
await this.GroupMeClient.GetGroupsAsync();
await this.GroupMeClient.GetChatsAsync();
var groupsAndChats = Enumerable.Concat<IMessageContainer>(this.GroupMeClient.Groups(), this.GroupMeClient.Chats());
foreach (var group in groupsAndChats)
{
// check the last-read message status from peristant storage
var groupState = this.SettingsManager.ChatsSettings.GroupChatStates.Find(g => g.GroupOrChatId == group.Id);
if (groupState == null)
{
groupState = new ChatsSettings.GroupOrChatState()
{
GroupOrChatId = group.Id,
LastTotalMessageCount = group.TotalMessageCount,
};
this.SettingsManager.ChatsSettings.GroupChatStates.Add(groupState);
}
// Code to update the UI needs to be run on the Application Dispatcher
// This is typically the case, but Timer events from ReliabilityStateMachine for
// retry-callbacks will NOT run on the original thread.
await Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(() =>
{
// calculate how many new messages have been added since the group/chat was last read
var unreadMessages = group.TotalMessageCount - groupState.LastTotalMessageCount;
if (unreadMessages < 0)
{
// strange errors can occur when the Group Listing lags behind the
// actual group contents. If this occurs, cancel and reload the sidebar.
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(async () => await this.LoadGroupsAndChats());
return;
}
var existingVm = this.AllGroupsChats.Items.FirstOrDefault(g => g.Id == group.Id);
if (existingVm == null)
{
// create a new GroupControl ViewModel for this Group
var vm = new GroupControlViewModel(group)
{
GroupSelected = new RelayCommand<GroupControlViewModel>(this.OpenNewGroupChat, (g) => true),
TotalUnreadCount = unreadMessages,
};
this.AllGroupsChats.Add(vm);
}
else
{
// Update the existing Group/Chat VM
existingVm.MessageContainer = group;
existingVm.TotalUnreadCount = unreadMessages;
}
var openChatGroup = this.ActiveGroupsChats.FirstOrDefault(g => g.Id == group.Id);
if (openChatGroup != null)
{
// chat is open and already receiving new messages, so mark all messages as "read"
existingVm.TotalUnreadCount = 0;
groupState.LastTotalMessageCount = openChatGroup.MessageContainer.TotalMessageCount;
}
});
}
this.SettingsManager.SaveSettings();
this.PublishTotalUnreadCount();
// if everything was successful, reset the reliability monitor
this.ReliabilityStateMachine.Succeeded();
this.RetryTimer?.Dispose();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Exception in {nameof(this.LoadGroupsAndChats)} - {ex.Message}. Retrying...");
this.RetryTimer = this.ReliabilityStateMachine.GetRetryTimer(async () => await this.LoadGroupsAndChats());
}
finally
{
this.ReloadGroupsSem.Release();
}
}
19
Source : TreeViewAdv.Input.cs
with MIT License
from AlexGyver
with MIT License
from AlexGyver
private void StopDragTimer()
{
if (_dragTimer != null)
{
_dragTimer.Dispose();
_dragTimer = null;
}
}
19
Source : DnsAsyncState.cs
with Apache License 2.0
from alexreinert
with Apache License 2.0
from alexreinert
internal void SetCompleted()
{
QueryData = null;
if (Timer != null)
{
Timer.Dispose();
Timer = null;
}
IsCompleted = true;
if (_waitHandle != null)
_waitHandle.Set();
if (UserCallback != null)
UserCallback(this);
}
19
Source : DnsClientAsyncState.cs
with Apache License 2.0
from alexreinert
with Apache License 2.0
from alexreinert
internal void SetCompleted()
{
QueryData = null;
if (Timer != null)
{
Timer.Dispose();
Timer = null;
}
IsCompleted = true;
if (_waitHandle != null)
_waitHandle.Set();
if (UserCallback != null)
UserCallback(this);
}
19
Source : RateGate.cs
with Apache License 2.0
from AlexWan
with Apache License 2.0
from AlexWan
protected virtual void Dispose(bool isDisposing)
{
if (!_isDisposed)
{
if (isDisposing)
{
// The semapreplaced and timer both implement IDisposable and
// therefore must be disposed.
_semapreplaced.Dispose();
_exitTimer.Dispose();
_isDisposed = true;
}
}
}
19
Source : AutoDelayTimers.cs
with MIT License
from AlphaYu
with MIT License
from AlphaYu
public void CloseTimer(string key)
{
if (_timers.ContainsKey(key))
{
if (_timers.TryRemove(key, out Timer timer))
{
timer?.Dispose();
}
}
}
19
Source : IDatabaseExtension.cs
with MIT License
from AlphaYu
with MIT License
from AlphaYu
public static async Task<(bool Success, string LockValue)> LockAsync(this IDatabase redisDb, string cacheKey, int timeoutSeconds = 5, bool autoDelay = true)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
ArgumentCheck.NotLessThanOrEqualZero(timeoutSeconds, nameof(timeoutSeconds));
var lockKey = GetLockKey(cacheKey);
var lockValue = Guid.NewGuid().ToString();
var timeoutMilliseconds = timeoutSeconds * 1000;
var expiration = TimeSpan.FromMilliseconds(timeoutMilliseconds);
bool flag = await redisDb.StringSetAsync(lockKey, lockValue, expiration, When.NotExists);
if (flag && autoDelay)
{
var refreshMilliseconds = (int)(timeoutMilliseconds / 2.0);
var autoDelayTimer = new Timer(timerState => Delay(redisDb, lockKey, lockValue, timeoutMilliseconds), null, refreshMilliseconds, refreshMilliseconds);
var addResult = AutoDelayTimers.Instance.TryAdd(lockKey, autoDelayTimer);
if (!addResult)
{
autoDelayTimer?.Dispose();
await redisDb.SafedUnLockAsync(cacheKey, lockValue);
return (false, null);
}
}
return (flag, flag ? lockValue : null);
}
19
Source : IDatabaseExtension.cs
with MIT License
from AlphaYu
with MIT License
from AlphaYu
public static (bool Success, string LockValue) Lock(this IDatabase redisDb, string cacheKey, int timeoutSeconds = 5, bool autoDelay = true)
{
ArgumentCheck.NotNullOrWhiteSpace(cacheKey, nameof(cacheKey));
ArgumentCheck.NotLessThanOrEqualZero(timeoutSeconds, nameof(timeoutSeconds));
var lockKey = GetLockKey(cacheKey);
var lockValue = Guid.NewGuid().ToString();
var timeoutMilliseconds = timeoutSeconds * 1000;
var expiration = TimeSpan.FromMilliseconds(timeoutMilliseconds);
var flag = redisDb.StringSet(lockKey, lockValue, expiration, When.NotExists);
if (flag && autoDelay)
{
var refreshMilliseconds = (int)(timeoutMilliseconds / 2.0);
var autoDelayTimer = new Timer(timerState => Delay(redisDb, lockKey, lockValue, timeoutMilliseconds), null, refreshMilliseconds, refreshMilliseconds);
var addResult = AutoDelayTimers.Instance.TryAdd(lockKey, autoDelayTimer);
if (!addResult)
{
autoDelayTimer?.Dispose();
redisDb.SafedUnLock(cacheKey, lockValue);
return (false, null);
}
}
return (flag, flag ? lockValue : null);
}
19
Source : OverlayForm.cs
with GNU General Public License v2.0
from AmanoTooko
with GNU General Public License v2.0
from AmanoTooko
protected override void Dispose(bool disposing)
{
if (this.zorderCorrector != null)
this.zorderCorrector.Dispose();
if (this.Renderer != null)
{
this.Renderer.Dispose();
this.Renderer = (Renderer) null;
}
if (this.surfaceBuffer != null)
this.surfaceBuffer.Dispose();
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
19
Source : HttpConnection.cs
with MIT License
from andruzzzhka
with MIT License
from andruzzzhka
private void disposeTimer ()
{
if (_timer == null)
return;
try {
_timer.Change (Timeout.Infinite, Timeout.Infinite);
}
catch {
}
_timer.Dispose ();
_timer = null;
}
19
Source : HttpBase.cs
with MIT License
from andruzzzhka
with MIT License
from andruzzzhka
protected static T Read<T> (Stream stream, Func<string[], T> parser, int millisecondsTimeout)
where T : HttpBase
{
var timeout = false;
var timer = new Timer (
state => {
timeout = true;
stream.Close ();
},
null,
millisecondsTimeout,
-1);
T http = null;
Exception exception = null;
try {
http = parser (readHeaders (stream, _headersMaxLength));
var contentLen = http.Headers["Content-Length"];
if (contentLen != null && contentLen.Length > 0)
http.EnreplacedyBodyData = readEnreplacedyBody (stream, contentLen);
}
catch (Exception ex) {
exception = ex;
}
finally {
timer.Change (-1, -1);
timer.Dispose ();
}
var msg = timeout
? "A timeout has occurred while reading an HTTP request/response."
: exception != null
? "An exception has occurred while reading an HTTP request/response."
: null;
if (msg != null)
throw new WebSocketException (msg, exception);
return http;
}
19
Source : InactivityTrackingService.cs
with MIT License
from angelobreuer
with MIT License
from angelobreuer
public void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
_timer?.Dispose();
}
19
Source : ISpeachController.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta
with BSD 3-Clause "New" or "Revised" License
from anoyetta
public static void SpeakWithDelay(
this ISpeechController speechController,
string text,
double delay,
PlayDevices playDevice = PlayDevices.Both,
VoicePalettes voicePalette = VoicePalettes.Default,
bool isSync = false,
float? volume = null)
{
if (delay == 0d)
{
speechController.Speak(text, playDevice, isSync, volume);
return;
}
var timer = new Timer(new TimerCallback((state) =>
{
speechController.Speak(text, playDevice, isSync);
(state as Timer).Dispose();
}));
timer.Change(
TimeSpan.FromSeconds(delay),
TimeSpan.Zero);
}
19
Source : BaseBatchMessageHandler.cs
with MIT License
from AntonyVorontsov
with MIT License
from AntonyVorontsov
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
if (disposing)
{
_timer?.Dispose();
Connection?.Dispose();
Channel?.Dispose();
}
_disposed = true;
}
19
Source : AmqpSendTask.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private static void OnOutcome(ILink link, global::Amqp.Message message, Outcome outcome, object state)
{
var thisPtr = (AmqpSendTask) state;
thisPtr.timer?.Dispose();
thisPtr.TrySetResult(outcome);
}
19
Source : AmqpSendTask.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private static void OnTimer(object state)
{
var thisPtr = (AmqpSendTask) state;
thisPtr.timer.Dispose();
thisPtr.TrySetException(new TimeoutException());
}
19
Source : XmlConfigurator.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void Dispose()
{
m_watcher.EnableRaisingEvents = false;
m_watcher.Dispose();
m_timer.Dispose();
}
19
Source : BasketObservableService.cs
with Apache License 2.0
from AppRopio
with Apache License 2.0
from AppRopio
private void OnProductAddToBasket(ProductAddToBasketMessage msg)
{
Task.Run(async () =>
{
try
{
var quanreplacedy = await ApiService.GetQuanreplacedy();
if (Mvx.IoCProvider.CanResolve<IMvxMessenger>() && Messenger.HreplacedubscriptionsFor<ModulesInteractionMessage<int>>())
Messenger.Publish(new ModulesInteractionMessage<int>(this, quanreplacedy) { Type = typeof(IBasketViewModel) });
else
{
Timer timer = null;
timer = new Timer((state) =>
{
if (timer != null && Mvx.IoCProvider.CanResolve<IMvxMessenger>() && Messenger.HreplacedubscriptionsFor<ModulesInteractionMessage<int>>())
{
Messenger.Publish(new ModulesInteractionMessage<int>(this, quanreplacedy) { Type = typeof(IBasketViewModel) });
timer?.Dispose();
timer = null;
}
}, timer, 1000, 1000);
}
}
catch (Exception ex)
{
Mvx.IoCProvider.Resolve<IMvxLog>().Warn($"{this.GetType().FullName}: {ex.BuildAllMessagesAndStackTrace()}");
}
});
}
19
Source : MarkedObservableService.cs
with Apache License 2.0
from AppRopio
with Apache License 2.0
from AppRopio
private void OnMarkedChanged(MvxMessage msg)
{
Task.Run(async () =>
{
try
{
var quanreplacedy = await ApiService.GetQuanreplacedy();
if (Mvx.IoCProvider.CanResolve<IMvxMessenger>() && Messenger.HreplacedubscriptionsFor<ModulesInteractionMessage<int>>())
Messenger.Publish(new ModulesInteractionMessage<int>(this, quanreplacedy) { Type = typeof(IMarkedViewModel) });
else
{
Timer timer = null;
timer = new Timer((state) =>
{
if (timer != null && Mvx.IoCProvider.CanResolve<IMvxMessenger>() && Messenger.HreplacedubscriptionsFor<ModulesInteractionMessage<int>>())
{
Messenger.Publish(new ModulesInteractionMessage<int>(this, quanreplacedy) { Type = typeof(IMarkedViewModel) });
timer?.Dispose();
timer = null;
}
}, timer, 1000, 1000);
}
}
catch (Exception ex)
{
Mvx.IoCProvider.Resolve<IMvxLog>().Warn($"{this.GetType().FullName}: {ex.BuildAllMessagesAndStackTrace()}");
}
});
}
19
Source : ValueAnimator.cs
with Apache License 2.0
from ascora
with Apache License 2.0
from ascora
protected virtual void RemoveFrameCallback()
{
_timer?.Dispose();
_timer = null;
}
19
Source : ValueAnimator.cs
with Apache License 2.0
from ascora
with Apache License 2.0
from ascora
protected virtual void Disposing(bool disposing)
{
if (_timer != null)
{
_timer.Dispose();
_timer = null;
}
if (Update != null)
foreach (EventHandler<ValueAnimatorUpdateEventArgs> handler in Update.GetInvocationList())
Update -= handler;
if (ValueChanged != null)
foreach (EventHandler handler in ValueChanged.GetInvocationList())
ValueChanged -= handler;
}
19
Source : EventSource.cs
with MIT License
from AshV
with MIT License
from AshV
private void CloseConnection()
{
if (ReadyState != EventSourceState.Connecting && ReadyState != EventSourceState.Open) return;
Trace.TraceInformation("CloseConnection");
if (_httpWebRequest != null)
{
_httpWebRequest.Abort();
}
if (_httpWebResponse != null)
{
_httpWebResponse.Close();
}
if (_retryTimer != null)
{
_retryTimer.Dispose();
}
_eventStream = null;
_eventId = null;
_eventType = null;
ReadyState = EventSourceState.Closed;
}
19
Source : ScheduleService.cs
with GNU Affero General Public License v3.0
from asmejkal
with GNU Affero General Public License v3.0
from asmejkal
public void Replan(TimeSpan delay, DateTime utcDueTime)
{
Timer?.Dispose();
Counter++;
UtcDueTime = utcDueTime;
Timer = new Timer(Callback, (ServerId, Counter), delay, new TimeSpan(Timeout.Infinite));
}
19
Source : ScheduleService.cs
with GNU Affero General Public License v3.0
from asmejkal
with GNU Affero General Public License v3.0
from asmejkal
public void Disable()
{
Timer?.Dispose();
Counter++;
UtcDueTime = null;
Timer = null;
}
19
Source : ScheduleService.cs
with GNU Affero General Public License v3.0
from asmejkal
with GNU Affero General Public License v3.0
from asmejkal
public void Dispose()
{
Timer?.Dispose();
((IDisposable)Lock).Dispose();
}
19
Source : ScheduleService.cs
with GNU Affero General Public License v3.0
from asmejkal
with GNU Affero General Public License v3.0
from asmejkal
public Task StopAsync(CancellationToken ct)
{
_updateTimer?.Dispose();
_updateTimer = null;
foreach (var notification in _notifications.Values)
notification.Disable();
return Task.CompletedTask;
}
19
Source : ScheduleService.cs
with GNU Affero General Public License v3.0
from asmejkal
with GNU Affero General Public License v3.0
from asmejkal
public void Dispose()
{
_updateTimer?.Dispose();
_updateTimer = null;
foreach (var notification in _notifications.Values)
notification.Dispose();
}
19
Source : LineProtocolPayloadClient.cs
with MIT License
from AspectCore
with MIT License
from AspectCore
public void Dispose()
{
_flushTimer.Dispose();
_logger?.LogInformation("Stop LineProtocolCollector.");
}
19
Source : ActiveHandlerTrackingEntry.cs
with Apache License 2.0
from aspnet
with Apache License 2.0
from aspnet
private void Timer_Tick()
{
Debug.replacedert(_callback != null);
Debug.replacedert(_timer != null);
lock (_lock)
{
_timer.Dispose();
_timer = null;
_callback(this);
}
}
19
Source : DefaultHttpClientFactory.cs
with Apache License 2.0
from aspnet
with Apache License 2.0
from aspnet
internal virtual void StopCleanupTimer()
{
lock (_cleanupTimerLock)
{
_cleanupTimer.Dispose();
_cleanupTimer = null;
}
}
19
Source : BackgroundDocumentGenerator.cs
with Apache License 2.0
from aspnet
with Apache License 2.0
from aspnet
private async void Timer_Tick(object state)
{
try
{
_foregroundDispatcher.replacedertBackgroundThread();
OnStartingBackgroundWork();
KeyValuePair<string, DoreplacedentSnapshot>[] work;
lock (_work)
{
work = _work.ToArray();
_work.Clear();
}
OnBackgroundCapturedWorkload();
for (var i = 0; i < work.Length; i++)
{
var doreplacedent = work[i].Value;
try
{
await doreplacedent.GetGeneratedOutputAsync();
}
catch (Exception ex)
{
ReportError(ex);
_logger.LogError("Error when processing doreplacedent: " + doreplacedent.FilePath);
}
}
OnCompletingBackgroundWork();
await Task.Factory.StartNew(
() =>
{
ReportUnsynchronizableContent(work);
NotifyDoreplacedentsProcessed(work);
},
CancellationToken.None,
TaskCreationOptions.None,
_foregroundDispatcher.ForegroundScheduler);
lock (_work)
{
// Resetting the timer allows another batch of work to start.
_timer.Dispose();
_timer = null;
// If more work came in while we were running start the worker again.
if (_work.Count > 0)
{
StartWorker();
}
}
OnCompletedBackgroundWork();
}
catch (Exception ex)
{
// This is something totally unexpected, let's just send it over to the workspace.
_logger.LogError("Unexpected error processing doreplacedent: " + ex.Message);
ReportError(ex);
_timer?.Dispose();
_timer = null;
}
}
19
Source : RazorDiagnosticsPublisher.cs
with Apache License 2.0
from aspnet
with Apache License 2.0
from aspnet
internal void ClearClosedDoreplacedents()
{
lock (_publishedDiagnostics)
{
var publishedDiagnostics = new Dictionary<string, IReadOnlyList<RazorDiagnostic>>(_publishedDiagnostics);
foreach (var entry in publishedDiagnostics)
{
if (!_projectManager.IsDoreplacedentOpen(entry.Key))
{
// Doreplacedent is now closed, we shouldn't track its diagnostics anymore.
_publishedDiagnostics.Remove(entry.Key);
// If the last published diagnostics for the doreplacedent were > 0 then we need to clear them out so the user
// doesn't have a ton of closed doreplacedent errors that they can't get rid of.
if (entry.Value.Count > 0)
{
PublishDiagnosticsForFilePath(entry.Key, Array.Empty<Diagnostic>());
}
}
}
_doreplacedentClosedTimer?.Dispose();
_doreplacedentClosedTimer = null;
if (_publishedDiagnostics.Count > 0)
{
// There's no way for us to know when a doreplacedent is closed at this layer. Therefore, we need to poll every X seconds
// and check if the currently tracked doreplacedents are closed. In practice this work is super minimal.
StartDoreplacedentClosedCheckTimer();
}
}
}
19
Source : RazorDiagnosticsPublisher.cs
with Apache License 2.0
from aspnet
with Apache License 2.0
from aspnet
private async void WorkTimer_Tick(object state)
{
DoreplacedentSnapshot[] doreplacedents;
lock (_work)
{
doreplacedents = _work.Values.ToArray();
_work.Clear();
}
for (var i = 0; i < doreplacedents.Length; i++)
{
var doreplacedent = doreplacedents[i];
await PublishDiagnosticsAsync(doreplacedent);
}
lock (_work)
{
// Resetting the timer allows another batch of work to start.
_workTimer.Dispose();
_workTimer = null;
// If more work came in while we were running start the timer again.
if (_work.Count > 0)
{
StartWorkTimer();
}
}
}
See More Examples