public static void CommandQueuePoller(CommandHandler service) { //Trace.WriteLine("LogPoller has started -- seeing if there's anything in the queue for me!!"); CloudQueueMessage msg = CommandQueue.GetMessage(); if (msg == null) { //Trace.TraceInformation("COMMAND QUEUE nothing found - going back to sleep"); } while (msg != null) { string myMessage = msg.AsString; Trace.TraceInformation("Got message {0}", myMessage); //probably should do some checking here before deleting... CommandQueue.DeleteMessage(msg); //split the ID from the type -- first item is ID, second is type string[] messageParts = myMessage.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (messageParts.Length != 2) { Trace.TraceError("COMMAND QUEUE message improperly formed. {0}", myMessage); continue; } CloudBlockBlob theBlob = CommandBlobContainer.GetBlockBlobReference(messageParts[0]); Type commandType = Type.GetType(messageParts[1]); CommandBase theCommand = null; using (MemoryStream msBlob = new MemoryStream()) { byte[] logBytes = theBlob.DownloadByteArray(); msBlob.Write(logBytes, 0, logBytes.Length); BinaryFormatter bf = new BinaryFormatter(); msBlob.Position = 0; object theObject = bf.Deserialize(msBlob); theCommand = Convert.ChangeType(theObject, commandType) as CommandBase; } if (theCommand != null) { service.Handle(theCommand); } else { Trace.TraceInformation("COMMAND BLOB Could not deserialize message from queue id {0}", myMessage); } msg = CommandQueue.GetMessage(); } }