This is a migrated thread and some comments may be shown as answers.

Using Async-methods to load appointments

1 Answer 88 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Chris Gårdenberg
Top achievements
Rank 2
Chris Gårdenberg asked on 25 Sep 2009, 02:57 PM
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:

        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, nullnull); 
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar Milushev
Telerik team
answered on 28 Sep 2009, 01:19 PM
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.
Tags
Scheduler
Asked by
Chris Gårdenberg
Top achievements
Rank 2
Answers by
Dimitar Milushev
Telerik team
Share this question
or