A newer version of this page is available. Switch to the current version.

FreeTimeCalculator.IntervalFound Event

This event is raised for each interval before it is added to the collection. It enables you to change a free interval after it is found.

Namespace: DevExpress.XtraScheduler.Tools

Assembly: DevExpress.XtraScheduler.v18.2.Core.dll


public event IntervalFoundEventHandler IntervalFound
Public Event IntervalFound As IntervalFoundEventHandler

Event Data

The IntervalFound event's data class is IntervalFoundEventArgs. The following properties provide information specific to this event:

Property Description
FreeIntervals Gets or sets a collection, containing the discovered free interval.
Resource Gets or sets a resource for appointments which are taken into account when a search for a free time is performed.


This event gives you the flexibility to decide whether a particular free time slot satisfies your requirements.

The FreeIntervals property of IntervalFoundEventArgs object provides access to a TimeIntervalCollectionEx collection, which contains a single element - the located time interval. You can edit this interval by modifying its start, end and duration.


The following example illustrates how the FreeTimeCalculator.IntervalFound event can be used to find the spare time periods in work time only within the work week.

To accomplish this, subscribe to the event and then call the FreeTimeCalculator.FindFreeTimeInterval method.

using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Tools;
// ...
private TimeInterval FindInterval(TimeInterval interval, TimeSpan duration) {            
    FreeTimeCalculator calculator = 
        new FreeTimeCalculator(schedulerControl1.Storage);
    // Set a handler for the IntervalFound event.
    calculator.IntervalFound += new IntervalFoundEventHandler(OnIntervalFound);            
    // Call the method which raises the event.
    TimeInterval freeInterval = calculator.FindFreeTimeInterval(interval, 
        duration, true);
    return freeInterval;
private void OnIntervalFound(object sender, IntervalFoundEventArgs args)
{   TimeIntervalCollectionEx freeIntervals = args.FreeIntervals;
    DateTime start = freeIntervals.Start.Date.AddDays(-1);
    DateTime end = freeIntervals.End;
    while (start < end) {
        RemoveSpareTime(freeIntervals, start);
        RemoveNonworkingDays(freeIntervals, start);
        start += TimeSpan.FromDays(1);
private void RemoveSpareTime(TimeIntervalCollectionEx freeIntervals, DateTime date) {
    TimeInterval spareTime = new TimeInterval(date.AddHours(18), 
private void RemoveNonworkingDays(TimeIntervalCollectionEx freeIntervals, 
DateTime date) {
    bool isWorkDay = schedulerControl1.WorkDays.IsWorkDay(date);
    if (!isWorkDay)
        freeIntervals.Remove(new TimeInterval(date, TimeSpan.FromDays(1)));            
See Also