hi i am using a window service application which was having a logic of dynamic threading generation which will use to create a separate thread based fetching data from the xml file for each individual attribute id, now my concern is i want to run those each threads in the different time intervals, one thread use to fire for every 5 min , another thread use to fire for every day mode, last thread should to be fire by monthly manner, can you please help me is it possible what i am thinking, when i start up a window service, all the thread to be start , these generated thread should not die even for the time being work was completed, we need set up a timer for those threads based on above i said,how can we perform that kindly advice...
here below i have pasted the same code of dynamic threading logic:
i want to know how set timer for each different thread
static void Main(string[] args)
{
var currentDir = Directory.GetCurrentDirectory();
var xDoc = XDocument.Load(string.Format(Path.Combine(currentDir, "Hosts.xml")));
var threads = new List<Thread>();
foreach (XElement host in xDoc.Descendants("Host"))
{
var hostID = (int)host.Attribute("id");
var extension = (string)host.Element("Extension");
var folderPath = (string)host.Element("FolderPath");
var thread = new Thread(DoWork)
{
Name = string.Format("samplethread{0}", hostID)
};
thread.Start(new FileInfo
{
HostId = hostID,
Extension = extension,
FolderPath = folderPath
});
threads.Add(thread);
}
// Carry on with your other work, then wait for worker threads
threads.ForEach(t => t.Join());
}
static void DoWork(object threadState)
{
var fileInfo = threadState as FileInfo;
if (fileInfo != null)
{
// Do stuff here
}
}
class FileInfo
{
public int HostId { get; set; }
public string Extension { get; set; }
public string FolderPath { get; set; }
}