public void RunAsync() { var timer = new UVTimer(); Loop.Default.RunAsync(); timer.Close(); }
public static void Main(string[] args) { Loop.Default.Run(async() => { var t = new UVTimer(); var now = DateTime.Now; await t.StartAsync(TimeSpan.FromSeconds(1)); Console.WriteLine(DateTime.Now - now); }); }
public static void Main(string[] args) { Loop.Default.Run(async() => { var t = new UVTimer(); var stopwatch = Stopwatch.StartNew(); await t.StartAsync(TimeSpan.FromSeconds(1)); stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); }); }
public static Task StartAsync(this UVTimer timer, long timeout) { var tcs = new TaskCompletionSource <object>(); try { timer.Start(timeout, () => { tcs.SetResult(null); }); } catch (Exception e) { tcs.SetException(e); } return(tcs.Task); }
public void Simple(int times, int spawn) { var t = new UVTimer(); int i = 0; t.Tick += () => { i++; if (i > times) { t.Close(); } }; t.Start(TimeSpan.FromMilliseconds(spawn)); var now = Loop.Default.Now; Loop.Default.Run(); Assert.GreaterOrEqual(Loop.Default.Now - now, (ulong)(times * spawn)); Assert.IsTrue(t.IsClosed); }
public static Task StartAsync(this UVTimer timer, ulong timeout) { var tcs = new TaskCompletionSource <object>(); #if TASK_STATUS HelperFunctions.SetStatus(tcs.Task, TaskStatus.Running); #endif try { timer.Start(timeout, () => { tcs.SetResult(null); }); } catch (Exception e) { tcs.SetException(e); } return(tcs.Task); }
public Fanbar(string root, int id) { Root = root; ID = id; Value = -1; timer = new UVTimer(Application.Loop); Get(PWM, (val) => { Invalid = true; Value = val; }); timer.Start(TimeSpan.FromSeconds(1), () => { Get(FanInput, (val) => RPM = val); }); }
public void Simple(int times, int spawn) { var t = new UVTimer(); int i = 0; t.Tick += () => { i++; if (i > times) { t.Close(); } }; t.Start(TimeSpan.FromMilliseconds(spawn)); var now = Loop.Default.Now; Loop.Default.Run(); Assert.True(Loop.Default.Now - now >= (ulong)(times * spawn)); Assert.True(t.IsClosed); }
public static Task StartAsync(this UVTimer timer, ulong timeout) { var tcs = new TaskCompletionSource <object>(); #if TASK_STATUS HelperFunctions.SetStatus(tcs.Task, TaskStatus.Running); #endif try { timer.Start(timeout, () => { #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. tcs.SetResult(null); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. }); } catch (Exception e) { tcs.SetException(e); } return(tcs.Task); }
public static void Main(string[] args) { var client = new UVIrcClient(); var bot = new IrcBot <UVIrcClient>(client); bot.Client.Connect("127.0.0.1", new IrcUserRegistrationInfo() { NickName = "txdv-bot", UserName = "******", RealName = "txdv bot", }); var adminPlugin = new AdminPlugin <UVIrcClient>("bentkus"); bot.Plugin(adminPlugin); bot.Plugin(new Greeter <UVIrcClient>()); bot.Plugin(new DatabasePlugin <UVIrcClient>(adminPlugin)); bot.Plugin(new JoinPlugin <UVIrcClient>(adminPlugin)); UVTimer.Once(TimeSpan.FromSeconds(1), () => client.Channels.Join("#help")); var stdin = new TTY(0); stdin.Read(Encoding.Default, (line) => { line = line.Trim(); switch (line) { case "quit": Loop.Default.Stop(); break; default: break; } }); stdin.Resume(); Loop.Default.Run(); }
public static Task StartAsync(this UVTimer timer, TimeSpan timeout) { return(timer.StartAsync((ulong)timeout.TotalMilliseconds)); }