private void QueryDispatchThreadRoutine()
{
bool InitialSync = true;
for (; ; )
{
//
// Run the query cycle and log any exceptions. Also, block
// ad-hoc modificatiosn to EventsQueued while we are running
// the query cycle (as we're prone to long blocking cycles
// there).
//
try
{
BlockEventsQueued = true;
if (!PauseUpdates)
{
//
// The first time around, download everything all at
// once so we don't have a round-trip for every new
// database object referenced.
//
if (InitialSync)
{
InitialSync = false;
PerformInitialSynchronization();
}
RunQueryCycle();
}
BlockEventsQueued = false;
//
// If we had held back on notifying the main thread that it
// should try and dequeue events, notify it now.
//
if (EventQueueModified)
{
EventQueueModified = false;
EventsQueued = true;
}
if (DatabaseOnline == false)
{
DatabaseOnline = true;
DistributeDatabaseOnlineNotification(true);
OnBroadcastNotification("Database connectivity restored.");
}
}
catch (Exception e)
{
//
// Try and log the exception. If that fails, don't take
// any other actions.
try
{
string ExceptionDescription = e.ToString();
WriteDiagnosticLog(String.Format(
"GameWorldManager.QueryDispatchThreadRoutine: Exception {0} running query cycle.", ExceptionDescription));
if (IsConnectivityFailureException(e, ExceptionDescription) &&
(DatabaseOnline == true))
{
DatabaseOnline = false;
DistributeDatabaseOnlineNotification(false);
OnBroadcastNotification("The server-side connection to the database has been lost.");
}
}
catch
{
}
}
QueryThreadWakeupEvent.WaitOne(DATABASE_POLLING_INTERVAL);
}
}