This is a question on how to maintain a C # stream while waiting for events.
I am writing a C # application that should launch an outlook instance (or reuse any existing instance if there is one active), create a mail item and show it, and then wait for the close event or send an event for the mail item,
The application will not be an add-in running inside Outlook, but will be executed from outside outlook to create an instance of outlook and mailitem.
Since my application does not work from gui outlook, but rather launches gui outlook, I somehow need to support my process until events are received (sending or closing). If my application returns and dies after displaying an Outlook message, my event handlers will also be dead.
Question: How should I support the application while waiting for events?
Since my thread is the one that creates the mail item and displays it in the Outlook window, is my thread responsible for not blocking the delivery of possible messages to the perspective window?
My thought was to have a method similar to this method to keep the process waiting
while(!MailClosed){ lock(mailLock){ Monitor.Wait(mailLock); } }
and then allow event handlers to send and close another method call to wake the waiter when they handle the event
private void SignalClose(){ lock(mailLock){ MailClosed = true; Monitor.Pulse(mailLock); } }
Would this block make possible messages from delivery to a perspective window containing my mail item? Does anyone have a better solution to handle this situation?
source share