Skip to content

Commit

Permalink
Добавлена документация для планировщика задач
Browse files Browse the repository at this point in the history
  • Loading branch information
OrnarasUS committed Jan 21, 2025
1 parent 72c9618 commit 20e2157
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Managers/TaskScheduler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace OrnaLibs.Managers
{
/// <summary>
/// Планировщик задач
/// </summary>
public static class TaskScheduler
{
private static TimeOnly?[] times = null!;
Expand All @@ -10,6 +13,11 @@ public static class TaskScheduler
private static int _interval;
private static Thread _thread = null!;

/// <summary>
/// Инициализация планировщика
/// </summary>
/// <param name="countTasks">Количество задач</param>
/// <param name="checkInterval">Интервал между проверками задач в секундах</param>
public static void Init(int countTasks, int checkInterval = 300)
{
times = new TimeOnly?[countTasks];
Expand All @@ -18,6 +26,12 @@ public static void Init(int countTasks, int checkInterval = 300)
_interval = checkInterval;
}

/// <summary>
/// Регистрация задачи
/// </summary>
/// <param name="time">Время, в которое будет срабатывать действие</param>
/// <param name="action">Действие</param>
/// <exception cref="OverflowException">Вызывается, когда отсутствует место для регистрации нового задачи</exception>
public static void RegisterTask(TimeOnly time, Action action)
{
if (nullIndex == actions.Length) throw new OverflowException();
Expand All @@ -27,6 +41,9 @@ public static void RegisterTask(TimeOnly time, Action action)
nullIndex++;
}

/// <summary>
/// Запуск планировщика
/// </summary>
public static void Start()
{
_thread = new(Loop)
Expand Down Expand Up @@ -62,6 +79,9 @@ private static void Loop()
}
}

/// <summary>
/// Отключение и освобожение планировщика
/// </summary>
public static void Dispose() => _thread.Interrupt();
}
}

0 comments on commit 20e2157

Please sign in to comment.