Using Async-methods to load appointments

2 posts, 1 answers
  1. Chris Gårdenberg
    Chris Gårdenberg avatar
    13 posts
    Member since:
    Nov 2008

    Posted 25 Sep 2009 Link to this post


    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) + ")"); 
                        companies = new DataTable(); 
                    //lblTest.Text = "Start: " + DateTime.Now.ToLongTimeString(); 
            private void EndLoadActivityData(IAsyncResult res) 
                //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, nullnull); 

    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.
  2. Answer
    Dimitar Milushev
    Dimitar Milushev avatar
    555 posts

    Posted 28 Sep 2009 Link to this post

    Hello Chris Gårdenberg,

    Can you please try using the Page.AddOnPreRenderCompleteAsync method to call the RadScheduler's Rebind() method instead of relying on the on the EndHandler of the PageAsyncTask?

    Sincerely yours,
    Dimitar Milushev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top