I've got two simple apps - one is a service & the other is a win form - the service counts messages in an inbox & sends emails, the win form uses the redemption dll to delete messages in an inbox. They both produce the same problem:
On each timer tick it takes a bit of memory each time, say 120k.
They start @ around 10k & I end up stopping them once they reach like 40k.
Anyone have any suggestions on how I should write more efficient code to prevent this from happening?
Thanks!!
Here's my code:
The service app:
Win Forms app:
Also, a side question with the win forms app:
When it deletes emails, If I have 8 messages in the inbox it will delete 4 on the first tick, 2 on the second, 1 on the 3rd - see the pattern - it only deletes half of the messages each tick. I want it to delete all 8 on every tick.
What's the deal with that?
Thanks ahead of time for the help!!!!
On each timer tick it takes a bit of memory each time, say 120k.
They start @ around 10k & I end up stopping them once they reach like 40k.
Anyone have any suggestions on how I should write more efficient code to prevent this from happening?
Thanks!!
Here's my code:
The service app:
VB.NET:
Imports System.Net.Mail
Imports Microsoft.Office.Interop
Public Class ExchangeMessageVerifier
Private SendTimer As System.Threading.Timer
Private AnalyzeTimer As System.Threading.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
Dim SendCallback As New Threading.TimerCallback(AddressOf OutgoingMailTimedEvent)
SendTimer = New System.Threading.Timer(SendCallback, Nothing, 10000, 10000)
StartOutlookClass.oApp.Session.Logon("testaccount", "testpw", False, False)
End Sub
Private Sub OutgoingMailTimedEvent(ByVal state As Object)
'Count Messages in Inbox. If there are zero messages, then notify Administrator.
Dim InboxMssgCount As Integer = StartOutlookClass.oApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items.Count
If (InboxMssgCount = 0) Then
' If zero messages then send notification email
Dim mail As New MailMessage()
mail.From = New MailAddress("ExchangeWatch@abc.com")
mail.To.Add("person@abc.com")
mail.Subject = "Emails are not being received"
mail.Body = "*Automatically Generated e-mail* <br> ExchangeWatch service is verifying internal e-mails are flowing succesfully."
mail.IsBodyHtml = True
Dim smtp As New SmtpClient("10.20.30.40")
smtp.Send(mail)
End If
End Sub
End Class
VB.NET:
Imports Redemption
Imports System.Net.Mail
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Delete all emails from inbox at specified interval
Const olFolderInbox As Redemption.rdoDefaultFolders = 6
Dim Session As New Redemption.RDOSession
Dim objFolder As Redemption.RDOFolder
Dim oItems As Object
Dim oItem As Redemption.RDOMail
Session.LogonExchangeMailbox("test@abc.com", "abc.123.com")
objFolder = Session.GetDefaultFolder(olFolderInbox)
oItems = objFolder.Items
For Each oItem In oItems
oItem.Delete(True)
Next
End Sub
End Class
Also, a side question with the win forms app:
When it deletes emails, If I have 8 messages in the inbox it will delete 4 on the first tick, 2 on the second, 1 on the 3rd - see the pattern - it only deletes half of the messages each tick. I want it to delete all 8 on every tick.
What's the deal with that?
Thanks ahead of time for the help!!!!
Last edited by a moderator: