Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Timeouts and freezing on loading or binding emails

$
0
0

I have a service that watches 2 email inboxes. One thread is created for each inbox. The new messages are read and marked as Read on startup, then the NewMail event handler handles all new mail after that.

We have been using EWS version 14. We had no issues retrieving emails.

After we moved the emails to Office 365, the problems started.

On startup, the retrieval and handling of existing new messages is still working fine.

After startup, when the NewMail event handler is triggered, the bind/load method times out, regardless of what we set the Timeout property to.

We tried to switch to the newest EWS version (15.0).

With the new version, the startup handling still works fine.

However, trying to bind one email in the NewMail event handler makes no error, but makes the inbox thread quit.

When there is a new email message in both inboxes, the entire service freezes on the Bind line (i let it sit for 40 minutes before having to kill the service).

We tried both EWS versions with the following, with no success:

The below code is used in the NewEmail event handler AND the startup processing of existing new messages. Why would the same code have issues in one place and not the other? How do i fix this?

I have also tried to use EmailMessage.Bind using the NotificationEventArgs object, but i have the same issues.

We tried a SyncLock to get around the lock up and/or timeout, but that did not help.

 Private Sub HaveMail(ByVal sender As Object, ByVal e As Microsoft.Exchange.WebServices.Data.NotificationEventArgs)
        Dim error_occured As Boolean = False
        Try
            Try
                SyncLock lock
                    Logger.LogDebug("Just entered the Locked state of the HaveMail event")
                    Dim ir As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, False), New ItemView(20))

                    Do While ir.Items.Count > 0
                        For Each i As EmailMessage In ir
                            Try
                                Logger.LogDebug("About to load a newly received email message")
                                i.Load(PropertySet.FirstClassProperties)
                            Catch ex As Exception
                                Throw New Exception("Error while loading an email message: " & ex.Message)
                            End Try
                            Dim rm As New ReceivedMessage
                            rm.ReceivedDateTime = i.DateTimeReceived
                            rm.ToAddress = i.DisplayTo
                            rm.Subject = i.Subject
                            rm.Body = i.Body
                            rm.FromAddress = i.From.Address
                            Logger.LogDebug("Just loaded a newly received email message from " & rm.FromAddress)
                            Dim rme As New ReceivedMessageEvent
                            rme.msg = rm
                            RaiseEvent GotMail(Me, rme)
                            Logger.LogDebug("Just processed a newly received email message from " & rm.FromAddress)
                            i.IsRead = True
                            i.Update(ConflictResolutionMode.AlwaysOverwrite)
                        Next
                        ir = service.FindItems(WellKnownFolderName.Inbox, New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, False), New ItemView(20))
                    Loop

                End SyncLock


Please help!

Thanks


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>