private void ScreenshotClicked(object sender, RoutedEventArgs e) { string fileName = DateTime.Now.Ticks.ToString(); PTools.Screenshot(fileName); statusUpdateLabel.Content = $"Screenshot saved @ {Directory.GetCurrentDirectory()} with name {fileName}"; }
static void Main(string[] args) { AsyncEnumerable <string> enumerable = new AsyncEnumerable <string>(() => new AsyncGenerator <string>((yield, complete) => { for (int x = 0; x < 25; x++) { Console.WriteLine($"Sending \"{pingData}\"... (#{x})"); yield(PTools.SendToWebSocket( new Uri("wss://echo.websocket.org"), () => $"{pingData}{rand.Next()}", (pingData.Length + 1) * 2 ) .Timeout(2500) .Then(bytes => Encoding.Unicode.GetString(bytes)) ); } })); Stopwatch watch = new Stopwatch(); watch.Start(); //The following two blocks of code do almost the same thing, but .ForeachAsync has promise error handling: //foreach (string s in enumerable) //{ // Console.WriteLine($"Received \"{s}\" in {watch.Elapsed}"); // watch.Restart(); //} //var enumeratePromise = enumerable // .ForeachAsync(s => // { // Console.WriteLine($"Received \"{s}\" in {watch.Elapsed}"); // watch.Restart(); // }) // .Catch(e => Console.WriteLine(e)); //enumeratePromise.Wait(); Console.WriteLine("Done!"); Console.ReadKey(); }
private void RestartClicked(object sender, RoutedEventArgs e) { statusUpdateLabel.Content = "Restarting now"; PTools.Shutdown(true); }
private void ShutdownClicked(object sender, RoutedEventArgs e) { statusUpdateLabel.Content = "Shutting down..."; PTools.Shutdown(false); }