Notice that the attribute is declared with AllowMultiple=true. This lets a function have multiple subscription declarations.
The final thing to notice is the IsBackground flag. If a subscriber is declared with IsBackground=true, then the event will be dispatched to the subscriber on a worker thread (internally, Begin/EndInvoke is used).
Here is the code:
using System;
// --------------------------------------------------------------------
//
// This code is (C) Copyright 2005 Marc Adler
//
// --------------------------------------------------------------------
namespace Magmasystems.EventManager
{
///
/// EventSubscriberAttribute
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple=true)]
public class EventSubscriberAttribute : System.Attribute
{
private string _topicName;
private bool _isBackground;
public EventSubscriberAttribute()
{
}
///
/// EventSubscriberAttribute
///
/// The name of the event
public EventSubscriberAttribute(string topicName)
{
this._topicName = topicName;
this._isBackground = false;
}
public string Topic
{
get
{
return this._topicName;
}
set
{
this._topicName = value;
}
}
public bool IsBackground
{
get
{
return this._isBackground;
}
set
{
this._isBackground = value;
}
}
}
}
©2006 Marc Adler - All Rights Reserved
No comments:
Post a Comment