I have the interface:
public interface IProcess
{
void Step_One();
void Step_Two();
Timer ProcessTimer{get; set;}
}
the base class..
public class ProcessBase
{
protected Timer processTimer;
public Timer ProcessTimer{get{ return processTimer;}set{processTimer=value;}}
//sets up all the common objects
public ProcessBase()
{
}
//This constructor will call the default constructor ^
protected ProcessBase(long intervalArg) : this()
{
processTimer = new Timer(intervalArg);
processTimer.Enabled = true;
}
}
the concrete class
public class ReportedContentProcess : ProcessBase, IProcess
{
public ReportedContentProcess(): base(5000)
{
}
public void Step_One()
{
}
public void Step_Two()
{
}
}
but when I try and get it out in a factory…
public static class ProcessFactory
{
public static List<IProcess> GetProcessors()
{
ReportedContentProcess.ReportedContentProcess reportedContentProcess = new ReportedContentProcess.ReportedContentProcess();
List<IProcess> retProcesses = new List<IProcess>();
retProcesses.Add(reportedContentProcess);
return retProcesses;
}
}
and then attach a handler to the timer…
processorsForService = ProcessFactory.GetProcessors();
foreach(IProcess p in processorsForService)
{
p.ProcessTimer.Elapsed += new ElapsedEventHandler(IProcess_Timer_Elapsed);
}
I get a run-time error saying that the p.ProcessTimer is null. Why is this? I have inherited and instantiated in the base class cant understand why its null. Ive even included it in the interface…
I see that you’re initializing
Timerin second constructor only. What if the default one is called (i.e. the constructor that is without params)?