Example #1
0
 private void SaveWorker()
 {
     while (true)
     {
         lock (_saveLock)
         {
             // NOTE: lock for the entire process so wait works in SaveWorld
             if (_saveQueue.Count > 0)
             {
                 SaveTask task = _saveQueue.Dequeue();
                 if (null == task)
                 {
                     return;
                 }
                 else
                 {
                     // Ensure that save handler errors don't bubble up and cause a recursive call
                     // These can be caused by an unexpected error such as a bad or out of date plugin
                     try
                     {
                         if (task.direct)
                         {
                             OnSaveWorld(new WorldSaveEventArgs());
                             WorldFile.RealSaveWorld(task.resetTime);
                         }
                         else
                         {
                             WorldFile.saveWorld(task.resetTime);
                         }
                         TShock.Utils.Broadcast("World saved.", Color.Yellow);
                         TShock.Log.Info(string.Format("World saved at ({0})", Main.worldPathName));
                     }
                     catch (Exception e)
                     {
                         TShock.Log.Error("World saved failed");
                         TShock.Log.Error(e.ToString());
                     }
                 }
             }
         }
         _wh.WaitOne();
     }
 }