Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

InfiniteTimeSpanConverter Class

Note: This class is new in the .NET Framework version 2.0.

Converts between a string and the standard infinite TimeSpan value.

Namespace: System.Configuration
Assembly: System.Configuration (in system.configuration.dll)

Public NotInheritable Class InfiniteTimeSpanConverter
	Inherits ConfigurationConverterBase
Dim instance As InfiniteTimeSpanConverter

public final class InfiniteTimeSpanConverter extends ConfigurationConverterBase
public final class InfiniteTimeSpanConverter extends ConfigurationConverterBase

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.

<ConfigurationProperty("timeDelay", _
DefaultValue:="infinite"), _
TypeConverter(GetType(InfiniteTimeSpanConverter))> _
Public Property TimeDelay() As TimeSpan
        Return CType(Me("timeDelay"), TimeSpan)
    End Get
    Set(ByVal value As TimeSpan)
        Me("timeDelay") = Value
    End Set
End Property

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() 
            Dim section As CustomSection = _
            ConfigurationManager.GetSection( _
            Console.WriteLine("timeDelay: {0", _
        Catch e As System.Exception
        End Try
    End Sub 'GetTimeDelay
    Public Shared Sub SetTimeDelay() 
            Dim config _
            As System.Configuration.Configuration = _
            ConfigurationManager.OpenExeConfiguration( _
            Dim section As CustomSection = _
            Dim td As New TimeSpan()
            td = _
            TimeSpan.FromMinutes( _
            section.TimeDelay = td
            section.SectionInformation.ForceSave = True
            Console.WriteLine("timeDelay: {0", _
        Catch e As System.Exception
        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"?>
    <section name="CustomSection" 
      Version=, Culture=neutral, 
      restartOnExternalChanges="true" />
    <CustomSection fileName="default.txt" maxIdleTime="90" timeDelay="infinite"/>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft