Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight WP7 messaging, should I use a WeakReference and if so how?
    primarykey
    data
    text
    <p>I'm creating a simple messaging system for a windows phone silverlight app.</p> <p>The idea is various xaml pages &amp; other objects will subscribe to a messaging object, passing in the type of message they want to recieve/handle and an Action&lt;> Delegate as the handler.</p> <p>When an action happens a message (with payload) will be sent to the correct subscribers.</p> <p>Here's a quick draft of what I want as the message class.</p> <pre><code>public class MessageBus { private List&lt;Subscriber&gt; subscribers; public MessageBus() { subscribers = new List&lt;Subscriber&gt;(); } public void Subscribe(string messageType, Action&lt;object&gt;subscriber){ subscribers.Add(new Subscriber(messageType, subscriber)); } public void SendMessage(object message, string messageType) { foreach (Subscriber subscriber in subscribers) { if (subscriber.MessageType == messageType &amp;&amp; subscriber.Reciever != null) { subscriber.Reciever(message); } } } } public class Subscriber { public string MessageType { get; set; } public Action&lt;object&gt; Reciever { get; set; } public Subscriber(string messageType, Action&lt;Object&gt; reciever) { MessageType = messageType; Reciever = reciever; } } </code></pre> <p>So varius subscribers will add themselves with a type, Action. As I understand this will stop the original pages/objects from being garbage collected (I assume it would be otherwise?) because a reference to it will always exist.</p> <p>I can't really unsubscribe, or not always anyway and the messaging queue will stay around for the lifetime of the application.</p> <p>Should I implement WeakReferences and if so how?</p> <p>Would WeakReferences add more overhead?</p> <p>Am I crazy to even consider this because the memory in use will be tiny?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload