Hi.
I'm trying to boost the performance by loading appointments with a async-method.
But it doesn't seem to work.
Here's my code:
And I call the function by running this code:
actList is a List<T>
If I run this without the async it works perfectly. Otherwise I get a blank scheduler, and some appointments in my actList.
I'm trying to boost the performance by loading appointments with a async-method.
But it doesn't seem to work.
Here's my code:
IAsyncResult beginLoad(Object sender, EventArgs e, AsyncCallback cb, object state) |
{ |
return loadActivityDataAsync(cb, state); |
} |
private void loadActivityData() |
{ |
DateTime startDate = radSched.VisibleRangeStart; |
//6 veckor |
DateTime endDate = radSched.VisibleRangeEnd; |
//Om sista veckan är helt utanför månaden |
actList = Activity.getActivities(Master.DB, Master.AresUser.UserID, startDate.AddMonths(-1), endDate.AddMonths(1), cbxShowCompleted.Checked); |
if (actList != null) |
{ |
string[] str = new string[actList.Count]; |
bool hasCompanies = false; |
for (int i = 0; i < str.Length; i++) |
{ |
hasCompanies = true; |
str[i] = actList[i].Company_Entityid.ToString(); |
} |
if (hasCompanies) |
companies = Master.DB.executeDataTable("SELECT * FROM company WHERE author_companyid = " + Master.AresUser.CompanyID + " AND entityID IN (" + string.Join(",", str) + ")"); |
else |
companies = new DataTable(); |
//lblTest.Text = "Start: " + DateTime.Now.ToLongTimeString(); |
} |
} |
private void EndLoadActivityData(IAsyncResult res) |
{ |
radSched.Rebind(); |
//lblTest.Text = "Stop: " + DateTime.Now.ToLongTimeString() + " Items: " + actList.Count; ; |
} |
private delegate void GenericDelegate(); |
private IAsyncResult loadActivityDataAsync(AsyncCallback cb, object state) |
{ |
GenericDelegate gd = loadActivityData; |
return gd.BeginInvoke(cb, state); |
} |
And I call the function by running this code:
PageAsyncTask task = new PageAsyncTask(beginLoad, EndLoadActivityData, null, null); |
Page.RegisterAsyncTask(task); |
actList is a List<T>
If I run this without the async it works perfectly. Otherwise I get a blank scheduler, and some appointments in my actList.