Silverlight WP7 messaging, should I use a WeakReference and if so how? -
I am creating a simple message system for a Windows Phone Registry app.
This idea is available in various Xaml pages & amp; Other objects will subscribe to Messaging Objects, they want to receive in the type of message they want to receive / Representative as an action & lt;> handler.
When there is an action (with payload) it is sent to the right customers.
Here's a quick draft of what I want as a message class.
public class messaging {Private list & lt; Subscriber & gt; Customers; Public Message () {Customers = New List & amp; Members, & gt; (); } Subscribe to Public Zero (String Message Type, Action & lt; Object & gt; Customer) {subscribers.Add (New Subscriber (Message Type, Customer)); } Public Zero SendMessage (object message, string message type) {foreach (subscriber subscriber in consumer) {if (customer message type == message type & amp; customer; receiver! = Tap) {customer. Receiver (message); }}}} Public class members {public string message type {get; Set; } Public Action & lt; Object & gt; Receiver {receives; Set; } Public Subscriber (String Message Type, Action & lt; Object & gt; Receiver) {MessageType = messageType; Receiver = Receiver; }}
Thus a different customer will automatically add one type of action. As I think the original pages / objects will be prevented from collecting garbage (I think it would be otherwise)? Because one reference will always be present.
I can not really end membership, or will not always be anyways and the message queue will remain around for the life of the application.
Should I apply weak references and if so how?
Will the weak reference increase more?
Am I crazy about this too because the usage will be very low?
The MVVM Light Toolkit is a cool loose coupling message and it is available for WP7
You may need it:
Comments
Post a Comment