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

RecurrenceRule in a custom Appointment class

2 Answers 152 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 07 Sep 2011, 07:54 AM
Hi,

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
        Get
            If Object.Equals(_masterEvent, Nothing) Then
                Return Nothing
            Else
                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.
        appointment.ApplySettingsToAppointment()
 
        '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.

Regards.


2 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 08 Sep 2011, 02:41 AM

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.

Regards.
0
Accepted
Ivan Todorov
Telerik team
answered on 12 Sep 2011, 08:50 AM
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.

Regards,
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 >>

Tags
Scheduler and Reminder
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Ivan Todorov
Telerik team
Share this question
or