private void OnAwaked() { var eventArgs = new WakeUpEventArgs(); OnWakeUp(eventArgs); Task.Run(async () => { var timeout = Task.Delay(TimeSpan.FromSeconds(5)); await Task.WhenAny(Task.WhenAll(eventArgs.WaitAll()), timeout); if (!timeout.IsCompleted) { try { await Sleep(); } catch { // NOP, device already sleeping } } }); }
protected virtual void OnWakeUp(WakeUpEventArgs e) { WakeUp?.Invoke(this, e); }