Platform SDK: MAPI

Ensuring a Thread-Safe Notification

If your client runs on a multithreaded platform such as Windows NT, you may need assurance that calls to your IMAPIAdviseSink::OnNotify methods occur on a particular thread. Because calls to OnNotify can typically occur on any thread, it is possible to receive notifications on unexpected and unwanted threads, leading to errors that are difficult to debug.

To guarantee that calls to OnNotify for a particular notification are made on the same thread that was used for the Advise call, call HrThisThreadAdviseSink before calling Advise. HrThisThreadAdviseSink creates a new advise sink object from your advise sink object. Pass this new object in the call to Advise. All clients with advise sink objects that might not work outside the context of a particular thread should always register advise sink objects created with HrThisThreadAdviseSink.

If your client runs on a 16-bit platform, you can call HrThisThreadAdviseSink if desired without any negative side effects; the only processing that occurs is an increment of the reference count on the original advise sink.