/// <summary> /// This method serves as the main thread of backend processing. /// The Run method should implement a long-running thread that carries // out operations /// </summary> public void Run() { while (true) { try { DataSources ds = new DataSources(); // Retrieve a new message from the queue. CloudQueueMessage msg = ds.WordQuque.GetMessage(TimeSpan.FromSeconds(1)); if (msg != null) { // Process the task. var messageParts = msg.AsString.Split(new char[] { ',' }); WordEntry entry = ds.GetWordEntry(messageParts[0], messageParts[1]); entry.Content = entry.Content.ToUpper(); entry.IsProcessed = true; ds.UpdateWordEntry(entry); // Delete message only when the task is completed. ds.WordQuque.DeleteMessage(msg); Trace.TraceInformation("Process result \"{0}\".", entry.Content); } else { Thread.Sleep(1000); } } catch (Exception ex) { Trace.TraceError("Exception when processing queue item. Message: '{0}'", ex.Message); System.Threading.Thread.Sleep(5000); } } }
public void UpdateWordEntry(WordEntry updatedItem) { _context.UpdateObject(updatedItem); _context.SaveChanges(); }
public void AddWordEntry(WordEntry newItem) { _context.AddObject("WordEntry", newItem); _context.SaveChanges(); }