TimeZoneInfo.ClearCachedData 메서드

정의

캐시된 표준 시간대 데이터를 지웁니다.

public:
 static void ClearCachedData();
public static void ClearCachedData();
static member ClearCachedData : unit -> unit
Public Shared Sub ClearCachedData ()

설명

캐시된 표준 시간대 데이터에는 현지 표준 시간대 및 UTC(협정 세계시) 영역에 대한 데이터가 포함됩니다.

이 메서드를 ClearCachedData 호출하여 애플리케이션의 표준 시간대 정보 캐시에 사용된 메모리를 줄이거나 로컬 시스템의 표준 시간대가 변경되었다는 사실을 반영할 수 있습니다.

로컬 및 UTC 표준 시간대에 대한 참조를 저장하는 것은 권장되지 않습니다. 메서드를 호출한 ClearCachedData 후 이러한 개체 변수는 더 이상 참조 TimeZoneInfo 되거나 TimeZoneInfo.Local참조되지 않는 정의 TimeZoneInfo.Utc 되지 않은 개체가 됩니다. 예를 들어 다음 코드에서 메서드에 대한 TimeZoneInfo.ConvertTime(DateTime, TimeZoneInfo, TimeZoneInfo) 두 번째 호출은 변수가 더 이상 같은 것으로 ArgumentException간주되지 않으므로 throw합니다 localTimeZoneInfo.Local.

TimeZoneInfo cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
TimeZoneInfo local = TimeZoneInfo.Local;
Console.WriteLine(TimeZoneInfo.ConvertTime(DateTime.Now, local, cst));

TimeZoneInfo.ClearCachedData();
try
{
   Console.WriteLine(TimeZoneInfo.ConvertTime(DateTime.Now, local, cst));
}
catch (ArgumentException e)
{
   Console.WriteLine(e.GetType().Name + "\n   " + e.Message);
}
open System

let cst = TimeZoneInfo.FindSystemTimeZoneById "Central Standard Time"
let local = TimeZoneInfo.Local
printfn $"{TimeZoneInfo.ConvertTime(DateTime.Now, local, cst)}"

TimeZoneInfo.ClearCachedData()
try
   printfn $"{TimeZoneInfo.ConvertTime(DateTime.Now, local, cst)}"
with :? ArgumentException as e ->
   printfn $"{e.GetType().Name}\n   {e.Message}"
Dim cst As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time")
Dim local As TimeZoneInfo = TimeZoneInfo.Local
Console.WriteLine(TimeZoneInfo.ConvertTime(Date.Now, local, cst))

TimeZoneInfo.ClearCachedData()
Try
   Console.WriteLine(TimeZoneInfo.ConvertTime(Date.Now, local, cst))
Catch e As ArgumentException
   Console.WriteLine(e.GetType().Name & vbCrLf & "   " & e.Message)
End Try

적용 대상