private void HandleConnection()
{
while (_communicator.Connected)
{
IResponse response;
Command message;
// Get a command
try
{
message = _communicator.WaitForMessage<Command>();
}
catch(TimeoutException)
{
// Timed out waiting for a message
Browser.Navigate("about:blank", false);
_communicator.Close();
return;
}
// Handle the command
try
{
response = HandleMessage(message);
}
catch (ThreadAbortException)
{
throw; // Shutting down
}
catch (Exception e)
{
response = message.CreateResponse(e);
}
if(response != null)
{
_communicator.SendResponse(response);
}
}
}