public void Start() { if (_index.index == 0) { throw new ObjectDisposedException(typeof(Schedule).FullName); } if (Time < 0) { Time = 0; } if (Interlocked.CompareExchange(ref _start, 1, 0) == 0) { _index.elapsed = Clock.Elapsed + Time * 1000; if (MainLoop.IsCurrent) { if (Interlocked.CompareExchange(ref _start, 2, 1) == 1) { schedules.Add(_index, this); } } else { MainLoop.Execute(() => { if (Interlocked.CompareExchange(ref _start, 2, 1) == 1) { schedules.Add(_index, this); } }); } } }
private void Dispose(bool disposing) { Index index = _index; Release(Interlocked.Exchange(ref _index.index, 0)); if (disposing) { if (Interlocked.Exchange(ref _start, 0) != 0) { if (MainLoop.IsCurrent) { schedules.Remove(index); } else { MainLoop.Execute(() => { schedules.Remove(index); }); } } } }