private async Task TryConnectServer(Object state) { var client = state as StarClient; await client.Login(); await CheckUpgrade(client); _timer.TryDispose(); _timer = new TimerX(CheckUpgrade, null, 600_000, 600_000) { Async = true }; }
protected override void OnStop() { _timer.TryDispose(); _timer = null; base.OnStop(); }
static void Test2() { var ic = Redis.Create("127.0.0.1", 3); // 简单操作 Console.WriteLine("共有缓存对象 {0} 个", ic.Count); var count = 2000000; Console.WriteLine("准备插入缓存{0:n0}项", count); var sw = Stopwatch.StartNew(); var prg = 0; var t = new TimerX(s => { XTrace.WriteLine("已处理 {0:n0} 进度 {1:p2} 速度 {2:n0}tps", prg, (Double)prg / count, prg * 1000 / sw.ElapsedMilliseconds); }, null, 1000, 1000); var buf = Rand.NextBytes(2800); for (var i = 0; i < count; i++) { var key = "BILL:" + (i + 1).ToString("000000000000"); ic.Set(key, buf, 48 * 3600); prg++; } t.TryDispose(); }
public Task StopAsync(CancellationToken cancellationToken) { _traceNode?.TryDispose(); _traceQueue?.TryDispose(); return(Task.CompletedTask); }
protected override void Dispose(Boolean disposing) { base.Dispose(disposing); clearTimer.TryDispose(); CloseAll(); }
private void TryConnectServer(Object state) { var client = state as StarClient; client.Login().Wait(); CheckUpgrade(client); // 登录成功,销毁定时器 //TimerX.Current.Period = 0; //_timer.TryDispose(); //_timer = null; _timer.TryDispose(); _timer = new TimerX(CheckUpgrade, null, 600_000, 600_000) { Async = true }; }
private static async Task TryConnectServer(Object state) { var client = state as StarClient; //var node = client.GetNodeInfo(); await client.Login(); // 登录成功,销毁定时器 _timer.TryDispose(); _timer = null; }
private static async Task TryConnectServer(Object state) { var client = state as StarClient; var set = XConfig.Current; await client.Login(); await CheckUpgrade(client, set.Channel); // 登录成功,销毁定时器 //TimerX.Current.Period = 0; _timer.TryDispose(); _timer = null; }
private void TryConnectServer(Object state) { var client = state as StarClient; var set = Setting.Current; client.Login().Wait(); CheckUpgrade(client, set.Channel); // 登录成功,销毁定时器 //TimerX.Current.Period = 0; _timer.TryDispose(); _timer = null; }
protected override void StopWork(String reason) { _timer.TryDispose(); _timer = null; foreach (var item in _ps) { item.Value.Stop(reason); } _ps.TryDispose(); base.StopWork(reason); }
private static void TryConnectServer(Object state) { var client = state as StarClient; var set = StarAgent.Setting.Current; //Task.Run(client.Login).ContinueWith(t => CheckUpgrade(client, set.Channel)); client.Login().Wait(); CheckUpgrade(client, set.Channel); // 登录成功,销毁定时器 //TimerX.Current.Period = 0; _timer.TryDispose(); _timer = null; }
private void StopTimer() { _timer.TryDispose(); _timer = null; #if !NET40 if (_websocket != null && _websocket.State == WebSocketState.Open) { _websocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "finish", default).Wait(); } _source?.Cancel(); //_websocket.TryDispose(); _websocket = null; #endif }
/// <summary>定时检查发送队列,超时未收到响应则重发</summary> /// <param name="state"></param> void Check(Object state) { var qs = Items; if (qs.Count == 0) { _Timer.TryDispose(); _Timer = null; return; } if (Interlocked.CompareExchange(ref _Checking, 1, 0) != 0) { return; } try { if (qs.Count == 0) { return; } var now = DateTime.Now; // 加锁复制以后再遍历,避免线程冲突 foreach (var qi in qs.ToArray()) { // 过期取消 if (qi.EndTime <= now) { qs.Remove(qi); if (!qi.Source.Task.IsCompleted) { qi.Source.SetCanceled(); } } } } finally { Interlocked.CompareExchange(ref _Checking, 0, 1); } }
/// <summary>销毁</summary> /// <param name="disposing"></param> protected override void Dispose(Boolean disposing) { base.Dispose(disposing); _timer.TryDispose(); }
public void Start() { var job = Job; // 参数检查 var expession = job.Cron; if (expession.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(job.Cron)); } var cmd = job.Method; if (cmd.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(job.Method)); } // 标识相同,不要处理 var id = $"{expession}@{cmd}"; if (id == _id && _timer != null) { return; } var cron = new Cron(); if (!cron.Parse(expession)) { throw new InvalidOperationException($"无效表达式 {expession}"); } // 找到类和方法 var p = cmd.LastIndexOf('.'); if (p <= 0) { throw new InvalidOperationException($"无效作业方法 {cmd}"); } var type = cmd.Substring(0, p).GetTypeEx(); var method = type?.GetMethodEx(cmd.Substring(p + 1)); if (method == null || !method.IsStatic) { throw new InvalidOperationException($"无效作业方法 {cmd}"); } _action = method.As <Action <String> >(); if (_action == null) { throw new InvalidOperationException($"无效作业方法 {cmd}"); } JobService.WriteLog("启用", true, $"作业[{job.Name}],定时 {job.Cron},方法 {job.Method}", job); // 实例化定时器,原定时器销毁 _timer.TryDispose(); _timer = new TimerX(DoJobWork, job, expession) { Async = true }; job.NextTime = _timer.NextTime; job.Update(); _id = id; }
void StopTimer() { clearTimer.TryDispose(); clearTimer = null; }
/// <summary> /// 关闭定时器 /// </summary> public static void StopTimer() { _timer.TryDispose(); _timer = null; }
public Task StopAsync(CancellationToken cancellationToken) { _timer.TryDispose(); return(Task.CompletedTask); }