InfiniteTimeSpanConverter Class
Converts between a string and the standard infinite TimeSpan value.
Assembly: System.Configuration (in System.Configuration.dll)
This type, like all the other configuration converter types, converts strings found in the configuration file to and from the related strongly typed properties.
In particular the InfiniteTimeSpanConverter converts the String value "infinite" assigned to a configuration property to the standard infinite TimeSpan and vice versa. The infinite TimeSpan value is represented by the MaxValue enumeration value.
This converter is used with TimeSpan properties. An infinite value is persisted as the "infinite" string.
The following code example shows how to define a custom section property that uses the InfiniteTimeSpanConverter class.
For the complete example code that implements the custom section, refer to the ConfigurationConverterBase class.
The following example code shows how to access the previous custom section property.
Imports System Imports System.IO Imports System.ComponentModel Imports System.Configuration NotInheritable Public Class UsingInfiniteTimeSpanConverter Public Shared Sub GetTimeDelay() Try Dim section As CustomSection = _ ConfigurationManager.GetSection( _ "CustomSection") Console.WriteLine("timeDelay: {0}", _ section.TimeDelay.ToString()) Catch e As System.Exception Console.WriteLine(e.Message) End Try End Sub 'GetTimeDelay Public Shared Sub SetTimeDelay() Try Dim config _ As System.Configuration.Configuration = _ ConfigurationManager.OpenExeConfiguration( _ ConfigurationUserLevel.None) Dim section As CustomSection = _ config.Sections.Get("CustomSection") Dim td As New TimeSpan() td = _ TimeSpan.FromMinutes( _ DateTime.Now.Minute) section.TimeDelay = td section.SectionInformation.ForceSave = True config.Save(ConfigurationSaveMode.Full) config.Save() Console.WriteLine("timeDelay: {0}", _ section.TimeDelay.ToString()) Catch e As System.Exception Console.WriteLine(e.Message) End Try End Sub 'SetTimeDelay End Class 'UsingInfiniteTimeSpanConverter
The following is a configuration excerpt as used by the previous example.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="CustomSection"
type="Samples.AspNet.CustomSection,
ConfigurationConverters,
Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"
allowDefinition="Everywhere"
allowExeDefinition="MachineToApplication"
restartOnExternalChanges="true" />
</configSections>
<CustomSection fileName="default.txt" maxIdleTime="90" timeDelay="infinite"/>
</configuration>
System.ComponentModel.TypeConverter
System.Configuration.ConfigurationConverterBase
System.Configuration.InfiniteTimeSpanConverter
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.