RecurrenceRule in a custom Appointment class

3 posts, 1 answers
  1. Richard
    Richard avatar
    32 posts
    Member since:
    Aug 2010

    Posted 07 Sep 2011 Link to this post


    I have created a custom Appointment class which implements Telerik.WinControls.UI.Appointment.
    I store a few fields in this class and they are stored in a database via a custom Edit Appointment Dialog.

    I have enabled the recurrence dialog recently and this works fine - can add a recurrence rule and this generates occurrences, etc. Looking at the other threads, I figured I had to include the following in my custom class for this to happen:
    Private _masterEvent As Telerik.WinControls.UI.IEvent
       Public Shadows ReadOnly Property MasterEvent() As Telerik.WinControls.UI.IEvent
                If Object.Equals(_masterEvent, Nothing) Then
                    Return Nothing
                    Return _masterEvent
                End If
            End Get
        End Property
        Public Overrides Function CreateOccurrence(start As Date) As Telerik.WinControls.UI.IEvent
            Dim appointment As New JobAppointment()
            Dim startDate As Date = start
            Dim ts As TimeSpan = Me.Duration
            Dim endDate As Date = startDate.Add(ts)
            'Added this to set the settings required by Telerik.
            'For repeated occurrences..
            Dim appType As Type = GetType(Telerik.WinControls.UI.Appointment)
            appType.GetField("masterEvent", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic).SetValue(appointment, Me)
            Return appointment
        End Function

    The issue I now face is that I want to store the RecurrenceRule in my database (right now recurrence only works in-memory). To do this, I have a string field "JobRecurrenceRule" which is stored in the database.

    When an appointment is to be saved to the database, I do the following:
    If RecurrenceRule IsNot Nothing Then
    If RecurrenceRule.IsValid Then
    JobRecurrenceRule = CalHelper.RecurrenceRuleToString(RecurrenceRule)
    End If
    End If

    When appointments are read from the database, I do the following to instantiate RecurrenceRule:
    If JobRecurrenceRule <> "" Then
                CalHelper.TryParseRecurrenceRule(JobRecurrenceRule, RecurrenceRule)
    End If

    The recurrence rule is being correctly saved to the database, but when I try to load the appointment back from the database, the scheduler seems to freeze. I get a context switch deadlock:

    ContextSwitchDeadlock was detected
    Message: The CLR has been unable to transition from COM context 0x4ac6f90 to COM context 0x4ac7100 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

    I have traced the freezing down to the code where I add the appointment with the RecurrenceRule to the RadScheduler.

    Commenting out the line:
    CalHelper.TryParseRecurrenceRule(JobRecurrenceRule, RecurrenceRule)

    Therefore, not reading the recurrence rule from the database, prevents this deadlock.

    I am assuming that something is not quite right with the way I am loading the RecurrenceRule from the database. Perhaps I am missing something? Any help much appreciated.


  2. Richard
    Richard avatar
    32 posts
    Member since:
    Aug 2010

    Posted 07 Sep 2011 Link to this post

    Okay, I think I have figured this out. CalHelper.TryParseRecurrenceRule does not set the Start property of the RecurrenceRule - it was Nothing, resulting in the freezing.

    I just needed to add an extra statement to load the recurrence rule from the database (JobRecurrenceRule String).
    If JobRecurrenceRule <> "" Then
          CalHelper.TryParseRecurrenceRule(JobRecurrenceRule, RecurrenceRule)
          RecurrenceRule.Start = Start
    End If

    Where Start is the Appointment instance's Start field.
    I hope I have got this right? It seems to be doing what ts supposed to.

  3. DevCraft R3 2016 release webinar banner
  4. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 12 Sep 2011 Link to this post

    Hi Richard,

    Thank you for contacting us.

    Yes, I can confirm that not setting the Start property results in a null reference exception. You should set the Start property manually to solve the issue.

    If you have any further questions, do not hesitate to write us.

    Ivan Todorov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top