Global event

Topics: CAB & Smart Client Software Factory
Oct 8, 2007 at 9:31 AM
Edited Oct 8, 2007 at 10:11 AM

After loading my application, I´d like to fire a global event to let my modules know, that they should synchronize themselfs with my remote server. Since there is no ModulesLoaded event, which would be the best place to fire this event? AfterShellCreated is being called before all modules have been loaded. Any ideas? Would it be the best to override the shellform´s onload?

Thaks a lot for your help in advance...
Oct 8, 2007 at 8:41 PM

The WorkItem class has the Initialized event that is fired once all modules have been loaded. You can add a handler for this event at the AfterShellCreated() method which would fire your event to synchronize the modules.

protected override void AfterShellCreated()
    RootWorkItem.Initialized += new EventHandler(RootWorkItem_Initialized);
private void RootWorkItem_Initialized(object sender, EventArgs e)
    this.Shell.OnSyncModules(new EventArgs());

But, the event publication cannot be in the ShellApplication.cs. Try putting it in the ShellForm.cs.

[EventPublication(EventTopicNames.SyncModules, PublicationScope.Global)]
public event EventHandler<EventArgs> SyncModules;
public virtual void OnSyncModules(EventArgs eventArgs)
    if (SyncModules != null)
        SyncModules(this, eventArgs);

For some additional information on the Initialized event, you can read this topic from CAB’s Help:
  • WorkItem.Initialized Event.

By the way, is there any reason why you really need that “All” modules are already loaded to synchronize them with the database? Any inter-module dependency?

Please let me know if this helps.

Ignacio Baumann Fonay
Oct 9, 2007 at 9:24 AM
Hi Ignacio.

Exactely what I was looking for. Thanks a lot.

Well I guess the modules have to be loaded to handle the global "synchronize" event.
When a module isn´t already loaded, it can´t fetch the event, can it?

The reason why we do this is:

We use a datetime field on our server-side database to track changes made to our data (i,e, LastChangeDate).
Since our users can use the application offline, the changes need to be synchronized with our server.

Using DSA we synchronize changes that were made offline. The other way round - when another user made changes and the client needs to synchronize the local datastore (sql compact), we query the server to send changed data using a timespan (last sync-date till now). This works pretty well.

But in some case it can happen, that another user synchronizes his data at the same moment as you do. In this case it can be, that your client isn´t aware of the newly changed data. Therefore we do some "full synchronization" at every start of the application using a longer timespan (i.e. past 3 weeks).

In our application every module handles and is responsible for it´s own data. Therefore every module (which subscribes the synchronize event) needs to be able to fetch this event at startup.

If there is a smarter solution, please let me know.

Thanks for your help.

PS: sorry for my poor english