开发者

Forcing a .Net IMAP service to quit

I've written an application that uses Outlook and Redemption to do some syncing operations with Exchange server over IMAP. It works great until it tries to exit. It executes the very last line of code, which is print "Service exiting" just fine, but this line occurs after the Application.Quit() call I make on Outlook. And the Outlook 2010 icon is still s开发者_开发百科itting in the task bar!

My question is: How can I force Outlook to close (even in a quick and dirty way) so that my application is guaranteed to quit, without hanging there waiting for Outlook to finish closing, which sometimes it just never does? (It waits for a user to right click the task bar icon and select 'Exit' instead)

TIA Dave --Trindaz on Fedang #Exchange-integration


I've never used Redemption, but it seems to be some tool that helps Automate Outlook in some way, and whenever you automate any Office application you always have to be careful to clear everything properly, otherwise it will be left with a hanging reference and might not shut down properly.

So, unless your usage of Redemption changes things in some way, I'd suggest that you might need to call Marshal.ReleaseComObject on any references to anything in Outlook that you use.

To be able to do that you have to be careful that you always store all the references that you access somewhere, so avoid doing nested calls like:

SomeOutlookObject.SomeInnerOutLookObject.SomeMethod

And instead do

Object innerObj = SomeOutlookObject.SomeInnerOutLookObject;
innerObj.SomeMethod

That way you can call ReleaseComObject on the innerObj as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜