If you trigger that function via the MCML layer (via a default rule in a UI etc) - either directly or via a .NET class - then you know the page is loaded and being displayed. (and the call to the .NET layer if done that way - will be in the correct thread).
Niall