{ "name": "Do stuff on process start/end", "language": 0, "code": "using System;\r\nusing System.Drawing;\r\n\r\npublic static class DisplayFusionFunction\r\n{\r\n\tpublic static void Run(IntPtr windowHandle)\r\n\t{\r\n\t\t// Set the process name here (case sensitive)\r\n\t\tstring processName = \"*notepad++.exe\";\r\n\r\n\t\t// Set the process checking timeout (in milliseconds) here\r\n\t\tuint processCheckWaitTime = 10000;\r\n\r\n\t\t// Set the \"cooldown\" timeout (in milliseconds) here\r\n\t\tuint cooldownTime = 30000;\r\n\r\n\t\t// Loop forever looking for the process\r\n\t\twhile (true)\r\n\t\t{\r\n\t\t\t// DEBUG\r\n\t\t\tBFS.General.LogText(\"Script: \\\"Do stuff on process start/end\\\" main loop starting (process exists check)...\");\r\n\r\n\t\t\t// If it's found do stuff\r\n\t\t\tif (BFS.Application.IsAppRunningByFile(processName))\r\n\t\t\t{\r\n\t\t\t\tBFS.General.LogText(\"Script: \\\"Do stuff on process start/end\\\" found process...\");\r\n\r\n\t\t\t\t// Wait 30 seconds to make sure it's still around\r\n\t\t\t\t// This prevents these actions from firing multiple times if the process closes/re-opens quickly\r\n\t\t\t\tBFS.General.ThreadWait(cooldownTime);\r\n\t\t\t\tif (BFS.Application.IsAppRunningByFile(processName))\r\n\t\t\t\t{\r\n\t\t\t\t\tBFS.General.LogText(\"Script: \\\"Do stuff on process start/end\\\" process still found, doing the process started stuff...\");\r\n\r\n\t\t\t\t\t// Stuff you want to do when the process has started\r\n\t\t\t\t\tBFS.DisplayFusion.RunFunctionAndWait(\"Function Name\");\r\n\r\n\t\t\t\t\t// Now periodically check if it's still running, then do stuff when it's not\r\n\t\t\t\t\twhile (true)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tBFS.General.LogText(\"Script: \\\"Do stuff on process start/end\\\" process gone loop starting...\");\r\n\r\n\t\t\t\t\t\tif (!BFS.Application.IsAppRunningByFile(processName))\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Wait 30 seconds to make sure it's gone for good\r\n\t\t\t\t\t\t\tBFS.General.ThreadWait(cooldownTime);\r\n\r\n\t\t\t\t\t\t\tif (!BFS.Application.IsAppRunningByFile(processName))\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tBFS.General.LogText(\"Script: \\\"Do stuff on process start/end\\\" process still gone, doing stuff...\");\r\n\r\n\t\t\t\t\t\t\t\t// Stuff you want to do when the process has ended\r\n\t\t\t\t\t\t\t\tBFS.DisplayFusion.RunFunctionAndWait(\"Function name\");\r\n\r\n\t\t\t\t\t\t\t\t// Exit the process ended check loop\r\n\t\t\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t// Wait 10 seconds before restarting the process ended loop\r\n\t\t\t\t\t\t\tBFS.General.ThreadWait(processCheckWaitTime);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t// Wait 10 seconds before restarting the process started loop\r\n\t\t\tBFS.General.ThreadWait(processCheckWaitTime);\r\n\t\t}\r\n\t}\r\n}", "description": "This script will loop in the background, looking for a process. It will do stuff when it detects the process has started, and do other stuff when it detects the process is gone.", "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.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.Forms.dll|System.Windows.Forms.Primitives.dll|System.Xml.dll" }