(Any One There)
I am working on vehicle tracking system:-
I have n number of buses say
b1t1(start at 7 am and stop at 7 pm)
bt2 (start at 8 am and stop at 8 pm) and bt3 (start at 9 am and stop at 9 pm)
,where t is start time of a bus
now i have such such busses in a list.
now for each bus in a list i pickup one busobject and pass to method MyMethod(bus bt);what i want is ,I want to pass b1,b2,b3 to MyMethod(bus bt) and and of each bus say b1--start its own proccessing of MyMethod(bus bt)
and then for b2 --start its own proccessing of MyMethod(bus bt)
and then for b3----start its own proccessing of MyMethod(bus bt)
all b1 b2 b3 should start there own processing in parallel (must be thread safe---isn it approprate to use word thread safe i donn know)....
---I tried using thread but thread does not acces the method in parallel...
more explanation i have only one method and will be passing bus object in a loop to MyMethod(bus bt) one by one ... but i want thread t1/t2...tn should access this method in parallel...because when thread for b1 is running simultinuously thread for b2 should run.
enter c public bool SchedulerEntryPointFunction()
{
Console.WriteLine("Scheduler is initiated !\n\n");
bool bSuccess = false;
Console.WriteLine("Got ActiveBuses and coresponding Paths!\n\n");
List<ActiveBusAndItsPathInfo> ActiveBusAndItsPathInfoList = BusinessLayer.GetActiveBusAndItsPathInfoList();
if (ActiveBusAndItsPathInfoList != null)
{
Thread[] threads = new Thread[ActiveBusAndItsPathInfoList.Count];
while (true)
{
foreach (ActiveBusAndItsPathInfo ActiveBusAndItsPathInfoObj in ActiveBusAndItsPathInfoList)
{
//Get curent time
//compare for time difference less than equal to 5 mins
if (ActiveBusAndItsPathInfoObj.isSMSThreadActive == false)
{
// Console.WriteLine("SMS Thread about to initiate!\n\n");
DateTime CurrentTime = System.DateTime.Now;
// TimeSpan CurrentTimespan = (TimeSpan)CurrentTime;
DateTime Bustime = Convert.ToDateTime(ActiveBusAndItsPathInfoObj.busObj.Timing);
//TimeSpan BustimeTimes = Bustime.TimeOfDay;
TimeSpan tsa = Bustime - CurrentTime;
// if(tsa.TotalMinutes > 0 && tsa.TotalMinutes < 5)
{
ActiveBusAndItsPathInfoObj.isSMSThreadActive = true;
***ThreadStart starter = delegate { SMSThreadEntryPointFunction(ActiveBusAndItsPathInfoObj); };
Thread t = new Thread(starter);
**// t.Start();
int indexOfCurrentActiveBusAndItsPathInfoObj = ActiveBusAndItsPathInfoList.IndexOf(ActiveBusAndItsPathInfoObj);
threads[indexOfCurrentActiveBusAndItsPathInfoObj] = new Thread(starter);
threads[indexOfCurrentActiveBusAndItsPathInfoObj].Start();
threads[indexOfCurrentActiveBusAndItsPathInfoObj].Join();***
}
}
}**
}
}
return bSuccess;
}
ode here
New Code:- Still giving synchronization issue...
foreach (ActiveBusAndItsPathInfo ActiveBusAndItsPathInfoObj in ActiveBusAndItsPathInfoList)
{
//Get curent time
//compare for time difference less than equal to 5 mins
if (ActiveBusAndItsPathInfoObj.isSMSThreadActive == false)
{
DateTime CurrentTime = System.DateTime.Now;
DateTime Bustime = Convert.ToDateTime(ActiveBusAndItsPathInfoObj.busObj.Timing);
TimeSpan tsa = Bustime - CurrentTime;
if(tsa.TotalMinutes > 0 && tsa.TotalMinutes < 5)
{
ActiveBusAndItsPathInfoObj.isSMSThreadActive = true;
ThreadPool.QueueUserWorkItem(state => SMSThreadEntryPointFunction(ActiveBusAndItsPathInfoObj)
}
}
}
}
return bSuccess;
}
do i have to lock my method ...SMSThreadEntryPointFunction(ActiveBusAndItsPathInfoObj)
currently i am trying
ThreadPool.QueueUserWorkItem(new WaitCallback(SMSThreadEntryPointFunction), (object)ActiveBusAndItsPathInfoObj);
but giving an error:-"No overload for SMSThreadEntryPointFunction matches delegate system.thread.WaitCallback"
(Any One There)