Module Loaded Event

Topics: Prism v2 - Silverlight 4
Sep 2, 2010 at 6:55 PM

Whats the best way to determine if a module has completed loading?

Sep 2, 2010 at 8:40 PM
Edited Sep 2, 2010 at 9:11 PM


Once the module assembly is transferred from disk into memory (process of loading a module), the State property is updated for each ModuleInfo object in the ModuleCatalog collection. Therefore, the recommended approach for achieving your scenario would be to look up in this collection and check the property. You could use a code like the following to check if a module has been loaded:
ModuleInfo info = catalog.Modules.First(m => m.ModuleName == "MyModule");
if (info.State == ModuleState.Initialized)     
    //your code here

As for how to know when your module has been loaded, you could raise an event from the Initializer method of your module to get notified. This could be achieved by using Event Aggregator, for more information on this topic, you could check the following documentation section on MSDN:

Additionally, this question was also treated in other forums thread, so you could take a  look at the following:

On the other hand, the modularity quickstarts (MEF and Unity) could be helpful, since they are logging all the states when loading their modules.

Please let me know if this helps.

Fernando Antivero