2014-12-10 1 views

답변

1

스톱워치의 인스턴스가 많거나 모든 애플리케이션에 대해 하나의 인스턴스가 필요합니까? 나는이 인스턴스를 얻을 수있는 클래스와 메소드의 개인 인스턴스를 생성 한 다음

private static Stopwatch _stopwatch = null; 
    public static Stopwatch Stopwatch 
    { 
     get 
     { 
      if (_stopwatch == null) 
       _stopwatch = new Stopwatch(); 

      return _stopwatch; 
     } 
     set { } 
    } 

: 마지막 경우에 당신은 App.xaml.cs를이 코드를 추가해야합니다.

1

예 싱글 톤 패턴을 사용할 수 있습니다. 링크를 참조하십시오. http://msdn.microsoft.com/en-us/library/ff650316.aspx

using System; 

public class Singleton 
{ 
    private static Singleton instance; 

    private Singleton() {} 

    public static Singleton Instance 
    { 
     get 
     { 
     if (instance == null) 
     { 
      instance = new Singleton(); 
     } 
     return instance; 
     } 
    } 
} 
관련 문제