CSLA

CSLA

Old forum URL: forums.lhotka.net/forums/t/12649.aspx


mayurimalgave posted on Wednesday, May 28, 2014

How to share information between multiple instances of Silverlight application in CSLA?

skagen00 replied on Wednesday, May 28, 2014

We do this quite heavily.

We maintain an isolated storage file containing the listener IDs of all instances, each of whom "register" themselves to the isolated storage file.

When it comes time to broadcast a message, we do something like the following.  (IntraApplicationMessage is just a class that contains information about the command that we created, and ToString() gets a string representation of it (like a serialization)). 

        /// <summary>

        /// Broadcasts the indicated message to all listeners.

        /// </summary>

        /// <param name="message">

        /// Message to broadcast.

        /// </param>

        internal static void BroadcastMessage(IntraApplicationMessage message)

        {

            var info = GetIsolatedStorageFile();

 

            foreach (string listener in info.ListenersList)

            {

                LocalMessageSender messageSender = new LocalMessageSender(listener, LocalMessageSender.Global);

 

                messageSender.SendCompleted += (o, e) =>

                {

                    if (e.Error != null)

                    {

                        // The message did not sent successfully - remove the listener.

                        UnregisterListener(e.ReceiverName);

                    }

                };

 

                // Fire off the message.

                messageSender.SendAsync(message.ToString());

            }

        }

Fundamentally though LocalMessageReceiver/LocalMessageSender is a good way to have SL instances talk back and forth with each other.

mayurimalgave replied on Thursday, May 29, 2014

Thank you.. We will try this out & get back with query if any..

Copyright (c) Marimer LLC