/// <summary> /// Internal thread procedure /// </summary> private static void ThreadProc() { // try to initiate the logfiles // fails for second startup due to writelock // so anything below the try catch has to nullcheck the streams! try { // create textlog stream logStream = new StreamWriter(LOGFILE, false, Encoding.Default); logStream.AutoFlush = true; // create textlog stream for chat logStreamChat = new StreamWriter(LOGFILECHAT, false, Encoding.Default); logStreamChat.AutoFlush = true; } catch (Exception) { } // (possibly) write startup headers WriteHeader(); WriteHeaderChat(); // (possibly) write logger start here Log(MODULENAME, LogType.Info, "Starting logger."); // start processing loop while (isRunning) { LogMessage item; string text; // process all pending items while (inputQueue.TryDequeue(out item)) { WriteLog(item); } // process all pending items for chat while (inputQueueChat.TryDequeue(out text)) { WriteLogChat(text); } // sleep Thread.Sleep(SLEEPTIME); } if (logStream != null) { logStream.Close(); logStream = null; } if (logStreamChat != null) { logStreamChat.Close(); logStreamChat = null; } }
private void ClearQueue(LockingQueue <CommandPacket> queue) { CommandPacket item; while (queue.TryDequeue(out item)) { item.Observer.OnCompleted(); } }
/// <summary> /// Starts preloading resources in several threads. /// </summary> /// <param name="Objects"></param> /// <param name="RoomTextures"></param> /// <param name="Rooms"></param> /// <param name="Sounds"></param> /// <param name="Music"></param> public void Preload(bool Objects, bool RoomTextures, bool Rooms, bool Sounds, bool Music) { Thread threadObjects = null; Thread threadRoomTextures = null; Thread threadRooms = null; Thread threadSounds = null; Thread threadMusic = null; if (PreloadingStarted != null) { PreloadingStarted(this, new EventArgs()); } if (Objects) { threadObjects = new Thread(LoadThreadObjects); threadObjects.Start(); } if (RoomTextures) { threadRoomTextures = new Thread(LoadThreadRoomTextures); threadRoomTextures.Start(); } if (Rooms) { threadRooms = new Thread(LoadThreadRooms); threadRooms.Start(); } if (Sounds) { threadSounds = new Thread(LoadThreadSounds); threadSounds.Start(); } if (Music) { threadMusic = new Thread(LoadThreadMusic); threadMusic.Start(); } string filename; // lock until all loaders are finished while ((threadObjects != null && threadObjects.IsAlive) || (threadRoomTextures != null && threadRoomTextures.IsAlive) || (threadRooms != null && threadRooms.IsAlive) || (threadSounds != null && threadSounds.IsAlive) || (threadMusic != null && threadMusic.IsAlive)) { while (queueAsyncFilesLoaded.TryDequeue(out filename)) { if (PreloadingFile != null) { PreloadingFile(this, new StringEventArgs(filename)); } } } while (queueAsyncFilesLoaded.TryDequeue(out filename)) { if (PreloadingFile != null) { PreloadingFile(this, new StringEventArgs(filename)); } } if (PreloadingEnded != null) { PreloadingEnded(this, new EventArgs()); } }