{ "name": "Sleep in 15 Seconds", "language": 0, "code": "using System;\r\nusing System.Drawing;\r\nusing System.Windows.Forms;\r\nusing System.Threading;\r\n\r\n// The 'windowHandle' parameter will contain the window handle for the:\r\n// - Active window when run by hotkey\r\n// - Trigger target when run by a Trigger rule\r\n// - TitleBar Button owner when run by a TitleBar Button\r\n// - Jump List owner when run from a Taskbar Jump List\r\n// - Currently focused window if none of these match\r\npublic static class DisplayFusionFunction\r\n{\r\n\tpublic static void Run(IntPtr windowHandle)\r\n\t{\r\n\t\tstring message = \"This computer will be put to sleep in 15 seconds.\";\r\n\t\tstring title = \"System going to sleep in 15 seconds\";\r\n\t\tint timeout = 15;\r\n\t\t\r\n\t\t// Run the messagebox on another thread so we can wait for it\r\n\t\tDialogResult result = DialogResult.OK;\r\n\t\tThread t = new Thread(() => result = MessageBox.Show(message, title, MessageBoxButtons.OKCancel));\r\n\t\tt.ApartmentState = ApartmentState.STA;\r\n\t\tt.Start();\r\n\t\t\r\n\t\t// Wait for the thread to stop with a timeout\r\n\t\tt.Join(timeout * 1000);\r\n\t\t\r\n\t\t// If the user cancelled exit the script\r\n\t\tif(result != DialogResult.OK)\r\n\t\t\treturn;\r\n\t\t\r\n\t\t// Find our messagebox window if it's still open and close it\r\n\t\tforeach(IntPtr window in BFS.Window.GetVisibleWindowHandles())\r\n\t\t{\r\n\t\t\tif(!BFS.Window.GetText(window).Equals(title))\r\n\t\t\t\tcontinue;\r\n\t\t\t\r\n\t\t\tBFS.Window.Close(window);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\t\r\n\t\t// Put the computer to sleep\r\n\t\tApplication.SetSuspendState(PowerState.Suspend, false, true);\r\n\t}\r\n}", "description": "", "references": "Microsoft.VisualBasic.Core.dll|Microsoft.Win32.Primitives.dll|Microsoft.Win32.Registry.dll|netstandard.dll|Newtonsoft.Json.dll|System.Collections.Concurrent.dll|System.Collections.dll|System.Collections.Immutable.dll|System.Collections.NonGeneric.dll|System.Collections.Specialized.dll|System.ComponentModel.Primitives.dll|System.ComponentModel.TypeConverter.dll|System.Console.dll|System.Core.dll|System.Data.dll|System.Diagnostics.Process.dll|System.dll|System.Drawing.Common.dll|System.Drawing.dll|System.Drawing.Primitives.dll|System.IO.Compression.dll|System.IO.dll|System.IO.FileSystem.Watcher.dll|System.Linq.dll|System.Linq.Expressions.dll|System.Linq.Parallel.dll|System.Linq.Queryable.dll|System.Management.dll|System.Net.dll|System.Net.Primitives.dll|System.Net.Requests.dll|System.Net.WebClient.dll|System.Net.WebHeaderCollection.dll|System.Private.CoreLib.dll|System.Private.Uri.dll|System.Private.Xml.dll|System.Runtime.dll|System.Runtime.InteropServices.dll|System.Runtime.Serialization.Formatters.dll|System.Security.Cryptography.Algorithms.dll|System.Security.Cryptography.Csp.dll|System.Security.Cryptography.dll|System.Security.Cryptography.Primitives.dll|System.Text.Json.dll|System.Text.RegularExpressions.dll|System.Threading.dll|System.Threading.Tasks.dll|System.Threading.Tasks.Parallel.dll|System.Web.dll|System.Web.HttpUtility.dll|System.Windows.Extensions.dll|System.Windows.Forms.dll|System.Windows.Forms.Primitives.dll|System.Xml.dll" }