title: Get unread email and mark as read in one call using EWS Managed API
body: <p>I have a standard routine to get an unread email from a mail server, mark it as read and then process it. It looks similar to this:</p>
  
  <pre><code>var view = new ItemView(1);
  SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
  var findResults = ExchangeService.FindItems(WellKnownFolderName.Inbox, sf, view);
  
  if (findResults.Items.Any())
  {
      EmailMessage emailMsg = findResults.Items.First() as EmailMessage;
      emailMsg.IsRead = true;
      emailMsg.Update(ConflictResolutionMode.AutoResolve);
  
      ProcessMail(emailMsg);
  }
  </code></pre>
  
  <p>This could be invoked from various processes, so I need to ensure atomicity of "find unread / mark as read" operation. In other words between <code>Service.FindItems()</code> and <code>mail.Update()</code> the same email could be read twice by different processes and result in duplicated processing.</p>
  
  <p>Now, I don't want to get involved in discussion about storing processed email IDs or whether I should be using multiple processes accessing the same email server.</p>
  
  <p>All I want to find out is if there is a EWS API method which does the two operations in one call? Ideally that would be something like this:</p>
  
  <pre><code>var mail = ExchangeService.GetFirstUnreadEmailAndMarkItAsRead()
  </code></pre>