Hello Nelson,
Then you probably also want to look that the ConfigurationSettings class
so that you can leverage the .NET Configuration API.
Create the configuration file, and then derive your custom objects from a
common interface, so that you can call an appropriate method to execute
the task.
For example:
public interface ITask
{
void Execute();
}
public class MySampleTask : ITask
{
public void Execute()
{
// do something in here
}
}
In your configuration file, put the type information for MySampleTask and
then use Activator.CreateInstance to load it.
Example:
Type type = Type.GetType(ConfigurationSettings.AppSettings["taskType"],
true);
ITask task = Activator.CreateInstance(type) as ITask;
if (task != null)
{
task.Execute();
}
else
{
// something happened and the type couldnt be loaded
}
The type will need to be referenced by a fully qualified name (ie:
namespace and assembly) in the config file.
Hope this helps!
--
Matt Berther
http://www.mattberther.com
Hi Matt,
Thank you for your response.
Here is what I would like to do:
<1> Create a Windows Service;
<2> Run some task every two hours or whatever interval
value setting in config file;
<3> In order to run this task, I need to create an instane
of some dll(assembly);
<4> Instead of adding a reference to this dll, I prefer to
load it from config file.
Please advise.
Nelson
and Activator.CreateInstance(type).