Outlook add-in C Sharp: While loop question
I'm writing a quick little add-in for Outlook tha开发者_如何学Got will check my email every x minutes and process the messages. This is my first add-in so I'm a little unsure of the order of runtime events, but the problem I'm having is that I'm using a while loop with a sleeper on my addin load event, which causes outlook to never fully open.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
while (true)
{
CheckMail();
System.Threading.Thread.Sleep(100000);
}
}
Is there a way I can fully open Outlook before executing this loop?
You could try hanging it off of a reminder event rather than sleeping it. To do this create a reminder. When it fires this code will get called. You can then throw CheckMail();
in there. This is in VBA so you will have to convert it.
Private Const REMINDER_SUBJECT As String = "CHECKEMAILREMINDER"
Private Sub Application_Reminder(ByVal Item As Object)
Dim oTask As Outlook.TaskItem
If TypeOf Item Is Outlook.TaskItem Then
Set oTask = Item
If oTask.Subject = REMINDER_SUBJECT Then
oTask.ReminderTime = DateAdd("m", 1, Now)
oTask.Save
End If
End If
End Sub
I searched for quite some time looking for a way to have regular events in outlook without using a reminder in order to archive my e-mail but this is the only solution I found.
精彩评论