Share via


Ensuring a Thread-Safe Notification

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

If your client runs on a multithreaded platform, 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.