ApplicationEvents_11_NewMailExEventHandler fires multiple times for a single email

P

Paddy

I have a simple test app that I have written to gain some knowledge
about the API for accessing Outlook using Visual Studio .NET

Relevant snippets are
........
while(true)
{
Application outlook = new Application();
outlook.NewMailEx += new
ApplicationEvents_11_NewMailExEventHandler(outlook_NewMailEx);


}


........
private static void outlook_NewMailEx(string EntryIDCollection)
{
Console.WriteLine("New mail arrived .... !");


}


I realise that there may be a problem with the "while(true)" part
(otherwise it simply exits when the process starts) but I was expecting

that when I send the test email, I should see only one line at the
console saying "New mail arrived ....!". Instead I see thousands !!

Any help is appreciated,
- K
 
L

Lebesgue

What are you doing is subscribing to the event infinite number of times.
What you probably want to do is:

(i assume you have a console application)

Application outlook = new Application();
outlook.NewMailEx += new
ApplicationEvents_11_NewMailExEventHandler(outlook_NewMailEx);
Console.ReadLine(); //this stops the current thread until you press enter in
the console

if you have winform application, just subscribe to the event in the
Form.Load event - and do it once J
 
P

Paddy

I solved it by creating a new thread and calling the delegate on it
..... But dang it, your solution is much more simpler !
Thanks,
- K
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top