Files
tgstation-server/TGControlPanel/ServerOpForm.cs
T
2017-11-11 17:27:58 -05:00

37 lines
931 B
C#

using System;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TGControlPanel
{
/// <summary>
/// Used to provide an ATP function for calls into an <see cref="TGServiceInterface.IInterface"/>
/// </summary>
#if !DEBUG
abstract class ServerOpForm : Form
#else
class ServerOpForm : Form
#endif
{
/// <summary>
/// Used to wrap <see cref="TGServiceInterface.IInterface"/> calls in a non-blocking fashion while disabling the <see cref="Form"/> and enabling the wait cursor
/// </summary>
/// <param name="action">The <see cref="TGServiceInterface.IInterface"/> operation to wrap</param>
/// <returns>A <see cref="Task"/> wrapping <paramref name="action"/></returns>
protected Task WrapServerOp(Action action)
{
Enabled = false;
UseWaitCursor = true;
try
{
return Task.Factory.StartNew(action);
}
finally
{
Enabled = true;
UseWaitCursor = false;
}
}
}
}