title: Multiple impersonation-threads in Exchange Web Service (EWS)
body: <p>I have a problem when running multiple impersonations of users in EWS, when I want to recieve notifications on each of the impersonated persons calendars (possible 100 persons).</p>
  
  <p>Currently I have an outlook account who have rights to impersonate all other users, and all the ExchangeService-objects get this accounts credentials</p>
  
  <p>Short version is, that when I try to bind to an appointment via the unique ID it works as long as I only have one thread running. When I start a new thread containing a new Exchangeservice with its own subscription I dont recieve any response on the Appointment.Bind()-request.</p>
  
  <p>When I run two instances of my program with only 1 thread in each it works fine, but as soon as I start a new thread with a new ExchangeService the Appointment.Bind() doesnt give any response.</p>
  
  <p>The weird part about this is, that it worked fine two weeks ago, but suddenly it stopped working and I didnt change my code.</p>
  
  <p>I have created a quick demo of my problem:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var x = new OutlookListener("user1@server.com");
          var y = new OutlookListener("user2@server.com");
          new Thread(x.Start).Start();
          new Thread(y.Start).Start();
          while (true)
          {
  
          }
      }
  }
  class OutlookListener
  {
      private ExchangeService _ExchangeService;
      private AutoResetEvent _Signal;
      public OutlookListener(string emailToImp)
      {
          _ExchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
          {
              Credentials = new NetworkCredential("superuser@server.com", "password"),
              Url = new Uri("exchangeUrl"),
              ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailToImp)
          };
      }
      public void Start()
      {
          var subscription = _ExchangeService.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Calendar },
                                                                    EventType.Created);
          var connection = CreateStreamingSubscription(_ExchangeService, subscription);
          Console.Out.WriteLine("Subscription created.");
          _Signal = new AutoResetEvent(false);
          _Signal.WaitOne();
          subscription.Unsubscribe();
          connection.Close();
      }
  
      private StreamingSubscriptionConnection CreateStreamingSubscription(ExchangeService service, StreamingSubscription subscription)                                                                         
      {
          var connection = new StreamingSubscriptionConnection(service, 30);
          connection.AddSubscription(subscription);
          connection.OnNotificationEvent += OnNotificationEvent;
          connection.OnSubscriptionError += OnSubscriptionError;
          connection.OnDisconnect += OnDisconnect;
          connection.Open();
  
          return connection;
      }
      private void OnNotificationEvent(object sender, NotificationEventArgs args)
      {
          // Extract the item ids for all NewMail Events in the list.
          var newMails = from e in args.Events.OfType&lt;ItemEvent&gt;()
                         where e.EventType == EventType.Created
                         select e.ItemId;
  
          foreach (var newMail in newMails)
          {
              var appointment= Appointment.Bind(_ExchangeService, newMail); //This is where I dont get a response!
              Console.WriteLine(appointment.Subject);
          }
      }
      private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
      {
      }
      private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
      {
      }
  }
  </code></pre>
  
  <p>Any suggestions?</p>