我想通过使用线程来优化性能。
public delegate int DelegateGetMarkOfSubject(int subjectid, int studentid);
int TotalMark = 0;
public void GetTotalMark(int StudentId)
{
TotalMark = 0;
List<Subjects> lstSubj = GetSubjectList(StudentId);
Waithandle[] waitHandler = new waitHandler[10];
DelegateGetMarkOfSubject delmarkOfSubj = new DelegateGetMarkOfSubject(GetMark);
foreach(var subject in lstSubj)
{
IAsync result_subject.id = delmarkOfSubj.BeginInvoke(subject.id, StudentId, new AsyncCallBack(GetMarkComplete), null);
waitHandler.add(result_subject.id.AsyncHandle);
}
WaitHandle.WaitAll(waitHandler);
return TotalMark;
}
GetMarkComplete(Iasynch argument)
{
DelegateGetMarkOfSubject del = (DelegateGetMarkOfSubject )((Asynchresult ar)).AsynDelegate;
newMark = del.EndInvoke(argument)
if(LockingCondition)
{
//PutLock
TotalMark += newMark;
//Release Lock
}
}