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

Customised Provider and thread safety

10 Answers 92 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 24 Nov 2010, 07:27 PM
Hi there,

I have been playing around with the Scheduler and have created a data provider that inherits from SchedulerProviderBase.  However, instead of instantiating the provider via web.config etc, I have instead created a new provider object each time the page is loaded (ie in Page_Load).  So, like this:

RadScheduler1.Provider = new SchedulerDataProvider( venueId, groupId );

This is so I can pass in some arguments to the provider so it returns different data based on the parameters sent in by the user.

This was all working fine until doing a postback from a dropdownlist in the page.  A that point, the standard " DataKeyField, DataSubjectField, DataStartField and DataEndField are required for databinding" exception was being thrown even before Page_Load is fired, as those fields are not set.

I got around this by just setting those fields to anything - that seemed to work and the scheduler managed to ignore the fact that it did not yet have any data (which is fine by me, as I need to reload the data each time).

However, when searching the Knowledge Base for help on the above, I came across the following:

The provider is instantiated once per application domain and is shared across threads. RadScheduler ensures basic thread safety by encapsulating each provider in a wrapper that provides locks around each of its public methods. However, you should take care of synchronizing access to instance field members where appropriate.

My question is this: I take it by doing what I am doing, the provider is NOT only instantiated the once, and a new one is created each time the page loads.  Is that the case?  Can I not worry about threading issues by doing it the way I am?  If not, any suggestions on how I should actually implement?

Thanks for your help.

Kind regards,

Matthew

 

10 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 29 Nov 2010, 02:10 PM
Hi Matthew,

The RadScheduler provider should be set in Page_Init. Please, see the attched demo for reference.
protected void Page_Init(object sender, EventArgs e)
   {
       var connString = ConfigurationManager.ConnectionStrings["TelerikVSXConnectionString"].ConnectionString;
       var factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
       RadScheduler1.Provider = new MyDbSchedulerProvider() { ConnectionString = connString, DbFactory = factory, PersistChanges = true };
   }


Peter
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Matthew
Top achievements
Rank 1
answered on 30 Nov 2010, 10:17 AM
Thanks Peter, I'll take a look at your example.  Thanks for taking the time to provide me with that.

Cheers,

Matthew
0
Matthew
Top achievements
Rank 1
answered on 14 Dec 2010, 01:08 PM
Hi Peter,

When setting the provider in the Page_Init event, I am getting the following error in very specific circumstances:

Insertion index was out of range. Must be non-negative and less than or equal to size.
Parameter name: index

[ArgumentOutOfRangeException: Insertion index was out of range. Must be non-negative and less than or equal to size.
Parameter name: index]
   System.Web.UI.StateManagedCollection.System.Collections.IList.set_Item(Int32 index, Object value) +1697056
   Telerik.Web.StronglyTypedStateManagedCollection`1.set_Item(Int32 index, ItemType value) +11
   Telerik.Web.UI.RadScheduler.Telerik.Web.UI.IScheduler.HandleMove(Appointment appointmentToMove, DateTime start, DateTime end, Boolean editSeries, ResourceUpdateInfo resourceUpdateInfo) +364
   Telerik.Web.UI.Scheduler.Views.Week.GroupedByResource.Model.HandleMove(Appointment appointment, ISchedulerTimeSlot sourceSlot, ISchedulerTimeSlot targetSlot, Boolean editSeries) +309
   Telerik.Web.UI.Scheduler.Views.SchedulerModel.ProcessPostBackCommand(SchedulerPostBackEvent postBack) +263
   Telerik.Web.UI.RadScheduler.ProcessPostBackCommand(SchedulerPostBackEvent postBack) +3455
   Telerik.Web.UI.RadScheduler.RaisePostBackEvent(String eventArgument) +62
   Telerik.Web.UI.RadScheduler.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


This happens when I do the following:

1) Load a scheduler with multiple resources (I am grouping by Date, then resource)
2) Move an appointment from one resource to another
3) Once the page has reloaded (I am not using Ajax), hit REFRESH
4) The error occurs.

This happens if I set the provider in page_load too.

To try and get around this I have set up a couple of web methods to deal with moving and resizing appointments, which work fine, but I can't figure out how to prevent postback from the scheduler once I have called my web methods (I can't just use the standard web service binding, because I absolutely need grouping by "Date, Resource").  So without setting args.set_cancel(true); in my client side methods I can't prevent postback, and if I do set cancel to true, my appointments revert to where they were or the size they were before.

Can you help me either with the first problem (the error on refresh) or the second (with preventing postback on appointment resizing or appointment moving)?

Thanks for your help.

Matthew




0
Veronica
Telerik team
answered on 21 Dec 2010, 02:16 PM
Hi Matthew,

Please accept my apologies for the late reply.

Unfortunately I was not able to reproduce the error. Could you please send me your code so I can inspect it and help you?

Thank you!

Kind regards,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Matthew
Top achievements
Rank 1
answered on 21 Dec 2010, 09:52 PM
Hi Veronica,

You can download an example project which shows the issue from here:

http://www.spawtz.com/TelerikExample.zip

(Sorry, could not attach to this message as wrong type and too big)

The code is a real mess - sorry about that.  I have stripped out all the actual data access code and substituted a "dummy" dataset creation function to mimic the real life code.  I've also stripped out a load of other stuff that references assemblies that I haven't included.  But you can reproduce the issue by following these steps:

1) Fire up the website
2) Move the fixture at 5pm on Court 2 to any other court
3) Wait for the page to reload
4) Hit Refresh in your browser
5) The error I reported occurs.

Thanks,

Matthew
0
Veronica
Telerik team
answered on 28 Dec 2010, 09:58 AM
Hello Matthew,

Please accept my apologies for the late reply.

After inspection of your code when I comment the Session settings in the Update method of your Provider - now the code doesn't throw ArgumentOutOfRange exception. However you've commented the code in the Update method and now when you try to move an appointment - actually nothing happens. Please take a look at this help topic about implementing a provider.

Kind regards,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Matthew
Top achievements
Rank 1
answered on 04 Jan 2011, 06:25 PM
Hi Veronica,

Yes, I know I have commented out all the update code - that's because I have not provided you with all the business logic, or the database that actually DOES the database update.  However, doing the update in session mimics the bug that is causing the refresh issue.

The link to the help topic you provided does not really help me - that IS pretty much how I have implemented the provider, but the issue seems to occur because once the update is done, and then a refresh is called on the page, the updated object no longer exists in the array or location it did before, so an exception is thrown even before I have a chance to catch or do anything with it.

Can you please suggest a way around this so I can actually release this into my live environment? - at the moment, this is preventing the control moving from Beta testing, as whenever someone refreshes the calendar after moving an appointment, they get this error.

Thanks,

Matthew
0
Veronica
Telerik team
answered on 07 Jan 2011, 09:57 AM
Hi Matthew,

Unfortunately I can not tell you what is the problem and how this can be solved as I can not see how you are updating the appointmens. Is there any way you can isolate the problem and send me a sample project with logic close to your original code?

Best wishes,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Matthew
Top achievements
Rank 1
answered on 09 Jan 2011, 03:40 PM
Veronica. 

The problem is not with the database code.  The problem is not with how the updates are occurring.  The problem, as demonstrated by the code I sent is that once the appointment has been moved, when the page is refreshed, the scheduler throws an exception.  The exception that you see being thrown when the appointment is moved in the session is the exception that is the problem.  So if we solve for that issue, we will solve for my issue where the changes are being persisted to the DB instead of to the session.

I am going to raise a ticket for this issue, as I really need some help on how to fix it.

Thanks,

Matthew
0
Veronica
Telerik team
answered on 13 Jan 2011, 10:28 AM
Hello Matthew,

The issue is fixed in the newly created support ticket. For those who follow the thread - the problem is in maintaining the ViewState of the RadScheduler. As resources are persisted in ViewState - you need to set the EnableViewState property to "true".

All the best,
Veronica Milcheva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Scheduler
Asked by
Matthew
Top achievements
Rank 1
Answers by
Peter
Telerik team
Matthew
Top achievements
Rank 1
Veronica
Telerik team
Share this question
or