hello ,
i have a asp.net application which pulls data from oracle database and load data into ms sql database . currently we are using year based static Threads. but the problem is when every year changes we need to create new thread and deploy the application
. can anyone help me to create Threads dynamically every year . bellow is my current code
public class Program
{
public static void Main(string[] args)
{
DataLoading dl1 = new DataLoading("2004");
Thread t1 = new Thread(dl1.LoadDatabyyear);
DataLoading dl2 = new DataLoading("2005");
Thread t2 = new Thread(dl2.LoadDatabyyear);
DataLoading dl3 = new DataLoading("2006");
Thread t3 = new Thread(dl3.LoadDatabyyear);
DataLoading dl4 = new DataLoading("2007");
Thread t4 = new Thread(dl4.LoadDatabyyear);
DataLoading dl5 = new DataLoading("2008");
Thread t5 = new Thread(dl5.LoadDatabyyear);
DataLoading dl6 = new DataLoading("2009");
Thread t6 = new Thread(dl6.LoadDatabyyear);
DataLoading dl7 = new DataLoading("2010");
Thread t7 = new Thread(dl7.LoadDatabyyear);
DataLoading dl8 = new DataLoading("2011");
Thread t8 = new Thread(dl8.LoadDatabyyear);
DataLoading dl9 = new DataLoading("2012");
Thread t9 = new Thread(dl9.LoadDatabyyear);
DataLoading dl10 = new DataLoading("2013");
Thread t10 = new Thread(dl10.LoadDatabyyear);
DataLoading dl11 = new DataLoading("2014");
Thread t11 = new Thread(dl11.LoadDatabyyear);
DataLoading dl12 = new DataLoading("2015");
Thread t12 = new Thread(dl12.LoadDatabyyear);
DataLoading dl13 = new DataLoading("2016");
Thread t13 = new Thread(dl13.LoadDatabyyear);
t1.Start();
t2.Start();
t3.Start();
t4.Start();
t5.Start();
t6.Start();
t7.Start();
t8.Start();
t9.Start();
t10.Start();
t11.Start();
t12.Start();
t13.Start();
Thread joinThread = new Thread(joinAllThread);
joinThread.Start(new Thread[] { t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13 });
}
private static void joinAllThread(object obj)
{
Thread[] threads = obj as Thread[];
foreach (Thread t in threads)
t.Join();
}
}
public class DataLoading
{
private string loadbyyear;
public DataLoading(string loadyear)
{
this.loadbyyear = loadyear;
}
public void LoadDatabyyear()
{
// LoadDatabyyear(loadbyyear); //some method
}
}
↧
Need Help On C# Multi Threading(Dynamic Threads)
↧