Detect Outlook /recycle state and run multiple instances of Outlook

主宰稳场 提交于 2020-12-31 08:44:25

问题


Is there a way to use code to detect whether Outlook will automatically grab an existing Outlook instance rather than starting a new Outlook instance? (Preferably VBA code.) Ideally, there would also be a way of switching on/off this behaviour programatically.

The objective here is to run multiple processes simultaneously against the data in one set of Outlook Accounts because some Outlook processes can take a long time. Long duration processes could then continue using one instance, while other short duration processes start and complete in another. Of course, care will be needed to ensure that processes use the correct instance of Outlook and that changes made by one instance do not compromise the behaviour of another.

By default, when launching Outlook 2013 or 2010, they automatically start up in a state that ensures that only one instance of Outlook runs. This is true even when you use VBA code like this:
Set appOl = CreateObject(Class:="Outlook.Application")

According to posts like http://amal.net/?p=2190 (2009) and http://www.nextofwindows.com/opening-multiple-instances-of-outlook-on-windows (uncertain date) this behaviour is specified by the use of the /recycle switch in the default Outlook launch shortcut that is created when Outlook is installed. Removal of the switch should prevent the behaviour and allow multiple instances of Outlook to be created. However installations of Outlook 2010 (on a Vista64 host) and Outlook 2013 (on a Windows 10 host) both behave as though the /recycle switch was present, even though their Outlook launch shortcuts do not include any /recycle argument.

Given a way to detect and, hopefully, to change the way Outlook behaves, code like this could be used to create an additional Outlook instance when a long running process is launched and to Quit the new Outlook instance it when it completes:

'       Detect whether a New Outlook instance can be created &
'         set the value of NewOutlookInstanceIsPossible to True/False
    If NewOutlookInstanceIsPossible Then
        Set appOl  = VBA.CreateObject(Class:="Outlook.application") 'New instance
    End If
'   ....     Code that does something using AppOl
    If NewOutlookInstanceIsPossible Then appOl.Quit                 'Quit new instance`

回答1:


Outlook is a singleton. It always runs only one instance per logged in user. Also keep in mind that all calls to the Outlook Object Model are marshaled to the main Outlook thread, so multithreading is not really possible.

To run multiple threads/processes, you'd need to use Extended MAPI (C++ or Delphi) which is a set of dlls loaded separately into each process. You can also use CDO 1.21 (no longer supported by Microsoft) or Redemption (use its RDO family of objects) - both of them are wrappers on top of Extended MAPi and can be used from multiple threads/processes.




回答2:


The short answer here is: If at all possible, don't run multiple threads on Outlook. If you absolutely have to do so, use Extended MAPI. This will probably require the purchase of something like Redemption or an alternative, if one exists.



来源:https://stackoverflow.com/questions/35381905/detect-outlook-recycle-state-and-run-multiple-instances-of-outlook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!