private static void PerformTask(Task t) { CurrentTaskId++; int tid = CurrentTaskId; try { Thread.BeginCriticalRegion(); // It is important that this task not be stopped here MinecraftModUpdater.Logger.Log(Logger.Level.Debug, "Running Task Id: " + tid.ToString()); if (t != null) { t.Invoke(); MinecraftModUpdater.Logger.Log(Logger.Level.Debug, "Task " + tid.ToString() + " Done"); } } catch (Exception e) { MinecraftModUpdater.Logger.Log(Logger.Level.Error, "Error on task " + tid.ToString()); MinecraftModUpdater.Logger.Log(e); MCModUpdaterExceptionHandler.HandleException(t, e); } finally { Thread.EndCriticalRegion(); // Thread can now be stopped. } }
void DoTaskAction(Task task, int startIndex, int endIndex) { for (var index = startIndex; index < endIndex; ++index) task.Invoke(index); if (task.IncrementTask() >= task.GetTaskCount()) task.SetFinished(); }