#region ================== Copyright (c) 2022 Boris Iwanski
/*
* This program is free software: you can redistribute it and/or modify
*
* it under the terms of the GNU General Public License as published by
*
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
*
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.If not, see.
*/
#endregion
#region ================== Namespaces
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CodeImp.DoomBuilder.Windows;
#endregion
namespace CodeImp.DoomBuilder.UDBScript
{
public partial class ScriptRunnerForm : DelayedForm
{
#region ================== Constants
///
/// How long a script is allowed to run until the form is made visible.
///
const int RUNTIME_THRESHOLD = 1000;
#endregion
#region ================== Variables
///
/// Cancellation token for stopping the script.
///
CancellationTokenSource cancellationtokensource;
///
/// If script is currently executed or not.
///
bool running;
///
/// How many milliseconds the script has been running
///
double runningseconds;
///
/// Determines if the form should be automatically closed when the script is finished.
///
bool autoclose;
///
/// Stopwatch used to determine how long the script is already running.
///
Stopwatch stopwatch;
///
/// Timer for making the form visible when the script is running for too long.
///
System.Windows.Forms.Timer timer;
#endregion
#region ================== Methods
public ScriptRunnerForm()
{
InitializeComponent();
}
///
/// Invokes a method, but stops the timer before running the code, and starting the timer after the code ran.
///
/// Method to invoke
/// Return value of the method
public object InvokePaused(Delegate method)
{
if (InvokeRequired)
{
return Invoke(new Func