mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* Fix AutoFishing crash * Fix all warnings * Remove DotNetZip. * Fix the usage of HttpClient.
43 lines
No EOL
1.3 KiB
C#
43 lines
No EOL
1.3 KiB
C#
using System;
|
|
using System.Threading;
|
|
|
|
namespace MinecraftClient
|
|
{
|
|
/// <summary>
|
|
/// Allow easy timeout on pieces of code
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// By ORelio - (c) 2014 - CDDL 1.0
|
|
/// </remarks>
|
|
public class AutoTimeout
|
|
{
|
|
/// <summary>
|
|
/// Perform the specified action with specified timeout
|
|
/// </summary>
|
|
/// <param name="action">Action to run</param>
|
|
/// <param name="timeout">Maximum timeout in milliseconds</param>
|
|
/// <returns>True if the action finished whithout timing out</returns>
|
|
public static bool Perform(Action action, int timeout)
|
|
{
|
|
return Perform(action, TimeSpan.FromMilliseconds(timeout));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Perform the specified action with specified timeout
|
|
/// </summary>
|
|
/// <param name="action">Action to run</param>
|
|
/// <param name="timeout">Maximum timeout</param>
|
|
/// <returns>True if the action finished whithout timing out</returns>
|
|
public static bool Perform(Action action, TimeSpan timeout)
|
|
{
|
|
Thread thread = new(new ThreadStart(action));
|
|
thread.Start();
|
|
|
|
bool success = thread.Join(timeout);
|
|
if (!success)
|
|
thread.Interrupt();
|
|
|
|
return success;
|
|
}
|
|
}
|
|
} |