Add-in multithreading

  • Thread starter Aleksander Tischenko
  • Start date
A

Aleksander Tischenko

Hi guys!
My add-in to MS Outlook during its work create several threads. This add-in
also working under Excel and Word, but only with Outlook I have problems.

I noticed that when Outlook is being unloaded it just kills all working
threads. Because of that my threads does not terminated correctly and I got
AV.

Does anyone experiencied with that?


Aleksandr.
 
D

Dmitry Streblechenko

Outlook itsel wouldn't care less about any threads it does not conrol - it
is your reposibility to shut down your threads or wait until they terminate
when Outlook unloads your add-in.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Aleksander Tischenko

Okay, just threads supposed to be destroyed in finalization section (I use
Delphi), and this working in any other office application like Word or
Excel. Additionaly I could not control Add-In unload event because my
product is a third-party control for outlook Add-in.

Anway, my customers fixed that by handing Outlook's OnQuit event.
Thanks!

Alex.
 
D

Dmitry Streblechenko

Do not do anything COM related in the initialization or finalization
sections in Delphi. OnQuit event or the destructor is a much better place to
do the cleanup.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Aleksander Tischenko

Thats very moot point, althought destroying threads are not com-relared
thing. And in any case application will not just kill its threads because
they may allocate important resources, lock devices etc.

Alex.
 
D

Dmitry Streblechenko

Well, when finalization section is executed, the dll is being unloaded and
quite a few things would be better off elsewhere, COM is just one example.
As for the threads, since they are yours, you can devise means to signal the
threads to exit by setting a flag/Win32 event on the main thread and waiting
for the thread to terminate, while the thread could check for the flag/event
every once in a while. If you don't gracefully terminate the threads and
wait for their completion, they will be killed regardless, but they will not
have a chance to exit gracefully.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Aleksander Tischenko

The finalization section contains code which correctly terminates all my
threads. And this code works great in all applications like Word, Excel, any
Delphi-application, but not in Outlook, because all my threads already
killed before this code being executed.
 
D

Dmitry Streblechenko

Did you try to move the thread termintion code from the finalization section
to your addin's class destructor?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
A

Aleksander Tischenko

Yes, it helps. See my second message :)

Dmitry Streblechenko said:
Did you try to move the thread termintion code from the finalization section
to your addin's class destructor?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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