<commit_before>using System;
using System.Threading;
using System.Timers;
using System.Windows.Forms;

namespace IronAHK.Rusty
{
    partial class Core
    {
        // TODO: organise Flow.cs

        /// <summary>
        /// Prevents the current thread from being interrupted by other threads.
        /// </summary>
        /// <param name="Mode">
        /// <list type="bullet">
        /// <item><term>On</term>: <description>give the current thread the highest priority.</description></item>
        /// <item><term>Off</term>: <description>resets the current thread priority to normal.</description></item>
        /// </list>
        /// </param>
        public static void Critical(string Mode)
        {
            bool on = OnOff(Mode) ?? true;
            System.Threading.Thread.CurrentThread.Priority = on ? ThreadPriority.Highest : ThreadPriority.Normal;
        }

        /// <summary>
        /// Exits the current thread.
        /// </summary>
        /// <param name="ExitCode">An integer that is returned to its caller when the program exits.</param>
        public static void Exit(int ExitCode)
        {
            Environment.ExitCode = ExitCode;
            Application.ExitThread();
        }

        /// <summary>
        /// Terminates the script unconditionally.
        /// </summary>
        /// <param name="ExitCode">An integer that is returned to its caller when the program exits.</param>
        public static void ExitApp(int ExitCode)
        {
            Environment.ExitCode = ExitCode;
            Application.Exit();
        }

        /// <summary>
        /// Checks if a function is defined.
        /// </summary>
        /// <param name="FunctionName">The name of a function.</param>
        /// <returns><c>true</c> if the specified function exists in the current scope, <c>false</c> otherwise.</returns>
        public static bool IsFunc(string FunctionName)
        {
            return FindLocalMethod(FunctionName) != null;
        }

        /// <summary>
        /// Checks if a label is defined.
        /// </summary>
        /// <param name="LabelName">The name of a label.</param>
        /// <returns><c>true</c> if the specified label exists in the current scope, <c>false</c> otherwise.</returns>
        public static bool IsLabel(string LabelName)
        {
            string method = LabelMethodName(LabelName);
            return FindLocalMethod(method) != null;
        }

        /// <summary>
        /// Specifies a label to run automatically when the application exits.
        /// </summary>
        /// <param name="Label">The name of a label. Leave blank to remove an existing label, if any.</param>
        public static void OnExit(string Label)
        {
            error = 0;

            if (onExit != null)
            {
                AppDomain.CurrentDomain.ProcessExit -= onExit;
                onExit = null;
            }

            if (string.IsNullOrEmpty(Label))
                return;

            var method = FindLocalRoutine(Label);

            if (method == null)
            {
                error = 1;
                return;
            }

            var handler = new EventHandler(delegate(object sender, EventArgs e)
            {
                method.Invoke(null, new object[] { new object[] { } });
            });

            AppDomain.CurrentDomain.ProcessExit += handler;
            onExit = handler;
        }<commit_msg>Safe OnExit method invoke.<commit_after>using System;
using System.Threading;
using System.Timers;
using System.Windows.Forms;

namespace IronAHK.Rusty
{
    partial class Core
    {
        // TODO: organise Flow.cs

        /// <summary>
        /// Prevents the current thread from being interrupted by other threads.
        /// </summary>
        /// <param name="Mode">
        /// <list type="bullet">
        /// <item><term>On</term>: <description>give the current thread the highest priority.</description></item>
        /// <item><term>Off</term>: <description>resets the current thread priority to normal.</description></item>
        /// </list>
        /// </param>
        public static void Critical(string Mode)
        {
            bool on = OnOff(Mode) ?? true;
            System.Threading.Thread.CurrentThread.Priority = on ? ThreadPriority.Highest : ThreadPriority.Normal;
        }

        /// <summary>
        /// Exits the current thread.
        /// </summary>
        /// <param name="ExitCode">An integer that is returned to its caller when the program exits.</param>
        public static void Exit(int ExitCode)
        {
            Environment.ExitCode = ExitCode;
            Application.ExitThread();
        }

        /// <summary>
        /// Terminates the script unconditionally.
        /// </summary>
        /// <param name="ExitCode">An integer that is returned to its caller when the program exits.</param>
        public static void ExitApp(int ExitCode)
        {
            Environment.ExitCode = ExitCode;
            Application.Exit();
        }

        /// <summary>
        /// Checks if a function is defined.
        /// </summary>
        /// <param name="FunctionName">The name of a function.</param>
        /// <returns><c>true</c> if the specified function exists in the current scope, <c>false</c> otherwise.</returns>
        public static bool IsFunc(string FunctionName)
        {
            return FindLocalMethod(FunctionName) != null;
        }

        /// <summary>
        /// Checks if a label is defined.
        /// </summary>
        /// <param name="LabelName">The name of a label.</param>
        /// <returns><c>true</c> if the specified label exists in the current scope, <c>false</c> otherwise.</returns>
        public static bool IsLabel(string LabelName)
        {
            string method = LabelMethodName(LabelName);
            return FindLocalMethod(method) != null;
        }

        /// <summary>
        /// Specifies a label to run automatically when the application exits.
        /// </summary>
        /// <param name="Label">The name of a label. Leave blank to remove an existing label, if any.</param>
        public static void OnExit(string Label)
        {
            error = 0;

            if (onExit != null)
            {
                AppDomain.CurrentDomain.ProcessExit -= onExit;
                onExit = null;
            }

            if (string.IsNullOrEmpty(Label))
                return;

            var method = FindLocalRoutine(Label);

            if (method == null)
            {
                error = 1;
                return;
            }

            var handler = new EventHandler(delegate(object sender, EventArgs e)
            {
                try { method.Invoke(null, new object[] { new object[] { } }); }
                catch (Exception) { }
            });

            AppDomain.CurrentDomain.ProcessExit += handler;
            onExit = handler;
        }
{'fraction_non_alphanumeric': 0.1187221182904015, 'fraction_numerical': 0.0005756223917110375, 'mean_word_length': 1.677195685670262, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372309', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1700, 'n_words': 520}