mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add 15 seconds timeout to session and login
Add AutoTimeout class for use on login and session requests. Bug report by GamerCorey7.
This commit is contained in:
parent
ee406b233e
commit
391eca102c
3 changed files with 72 additions and 23 deletions
41
MinecraftClient/AutoTimeout.cs
Normal file
41
MinecraftClient/AutoTimeout.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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="attempts">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="attempts">Maximum timeout</param>
|
||||
/// <returns>True if the action finished whithout timing out</returns>
|
||||
public static bool Perform(Action action, TimeSpan timeout)
|
||||
{
|
||||
Thread thread = new Thread(new ThreadStart(action));
|
||||
thread.Start();
|
||||
bool success = thread.Join(timeout);
|
||||
if (!success)
|
||||
thread.Abort();
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue