コード例 #1
0
 static public void AddListener(string eventType, cCallback handler)
 {
     // Obtain a lock on the event table to keep this thread-safe.
     lock (eventTable)
     {
         // Create an entry for this event type if it doesn't already exist.
         if (!eventTable.ContainsKey(eventType))
         {
             eventTable.Add(eventType, null);
         }
         // Add the handler to the event.
         eventTable[eventType] = (cCallback)eventTable[eventType] + handler;
     }
 }
コード例 #2
0
ファイル: cMessenger.cs プロジェクト: qtLex/Good_Evil_Level_1
 public static void AddListener(string eventType, cCallback handler)
 {
     // Obtain a lock on the event table to keep this thread-safe.
     lock (eventTable)
     {
         // Create an entry for this event type if it doesn't already exist.
         if (!eventTable.ContainsKey(eventType))
         {
             eventTable.Add(eventType, null);
         }
         // Add the handler to the event.
         eventTable[eventType] = (cCallback)eventTable[eventType] + handler;
     }
 }
コード例 #3
0
    static public void Invoke(string eventType)
    {
        Delegate d;

        // Invoke the delegate only if the event type is in the dictionary.
        if (eventTable.TryGetValue(eventType, out d))
        {
            // Take a local copy to prevent a race condition if another thread
            // were to unsubscribe from this event.
            cCallback callback = (cCallback)d;

            // Invoke the delegate if it's not null.
            if (callback != null)
            {
                callback();
            }
        }
    }
コード例 #4
0
    static public void RemoveListener(string eventType, cCallback handler)
    {
        // Obtain a lock on the event table to keep this thread-safe.
        lock (eventTable)
        {
            // Only take action if this event type exists.
            if (eventTable.ContainsKey(eventType))
            {
                // Remove the event handler from this event.
                eventTable[eventType] = (cCallback)eventTable[eventType] - handler;

                // If there's nothing left then remove the event type from the event table.
                if (eventTable[eventType] == null)
                {
                    eventTable.Remove(eventType);
                }
            }
        }
    }
コード例 #5
0
ファイル: cMessenger.cs プロジェクト: qtLex/Good_Evil_Level_1
    public static void RemoveListener(string eventType, cCallback handler)
    {
        // Obtain a lock on the event table to keep this thread-safe.
        lock (eventTable)
        {
            // Only take action if this event type exists.
            if (eventTable.ContainsKey(eventType))
            {
                // Remove the event handler from this event.
                eventTable[eventType] = (cCallback)eventTable[eventType] - handler;

                // If there's nothing left then remove the event type from the event table.
                if (eventTable[eventType] == null)
                {
                    eventTable.Remove(eventType);
                }
            }
        }
    }