Handling Occurrences for Exceptions
Handling Occurrences for Exceptions
When defining recurring exceptions in a project calendar, such as annual holidays or seasonal shutdowns, it’s important to specify how many times the exception should repeat. In Aspose.Tasks for .NET, the
Occurrences
property of the
CalendarException
class is used for this purpose.
This property accepts an integer value indicating the number of times the exception will occur starting from the defined FromDate
. For example, if the exception represents an annual holiday, setting Occurrences = 5
will apply the exception over five years.
Example: Define Exception for Multiple Occurrences
The following code example shows how to create a calendar exception that repeats annually for five years:
1// Define exception and specify occurrences
2CalendarException except = new CalendarException();
3except.EnteredByOccurrences = true;
4except.Occurrences = 5;
5except.Type = CalendarExceptionType.YearlyByDay;
{{}}
Conclusion
Using the Occurrences
property allows you to define recurring exceptions in a structured and controlled manner. This is particularly useful for automating non-working days such as holidays that occur every year over the duration of a long-term project.
For related scenarios, refer to: