You should check for null when raising events in C#
if( DataEvent != null ) DataEvent(list);
Also, usually event delegates follow the format of:
void EventName(object sender, EventArgs e)
where e is either the EventArgs class or some class that derives from it. In this case something like the following is best:
Code:
public class DataEventArgs : EventArgs
{
private ArrayList _list;
public ArrayList FileList { get { return _list; } set { _list = value; } }
}
public void DataEventEventHandler(object sender, DataEventArgs e)
public event DataEventEventHandler DataEvent;
public void SearchFiles(ArrayList list)
{
DataEventArgs e = new DataEventArgs();
e.FileList = list;
if( DataEvent != null ) DataEvent(this, e); //raising event for testing
}
To consume the event you then do the usual:
[code]
RaiseEventClass c = new RaiseEventClass();
c.DataEvent += new DataEventEventHandler(My_DataEvent);
//elsewhere define the method
public void My_DataEvent(object sender, DataEventArgs e)
{
// Do something with the list...
// e.FileList
}
/- Sam Judson : Wrox Technical Editor -/