2013-08-30 2 views
3

간단한 스톱워치 WPF 응용 프로그램을 만들려고합니다. 여기System.Diagnostics.Stopwatch에 대한 참조를 찾을 수 없습니다.

enter image description here

내가 System.Diagnostics 네임을 사용하고 있지만, 어떤 이유로 나는 Stopwatch

에 액세스 할 수 있으며, 내가 할 수있는

using System; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Diagnostics; 

namespace WpfApplication1 
{ 
/// <summary> 
/// Interaction logic for App.xaml 
/// </summary> 
public partial class App : Application 
{ 
    public stopWatch = new Stopwatch(); 

    private void startTimer() 
    { 
     stopWatch.Start(); 
     Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(ShowElapsedTime)); 
    } 
    void ShowElapsedTime() 
    { 
     TimeSpan ts = stopWatch.Elapsed; 
     lblTime.Text = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds/10); 
    } 
} 
} 

과 : 여기

내 코드입니다 이 대화에서 System.Diagnostics를 찾을 수 없습니다 :

enter image description here

System.Diagnostics.Stopwatch를 사용할 수없는 이유는 무엇이며 System.Diagnostics가 참조 대화 상자에 나타나지 않는 이유는 무엇입니까?

+1

코드는 텍스트입니다. 사진을 복사 할 때 * 텍스트로 * 붙여 넣을 때 훨씬 쉽게 볼 수 있습니다 (사진이 현재 화면에 작아짐). –

+0

'System.Diagnostics'는'System.dll' 내에 있습니다. 나는 빈 콘솔 애플리케이션을 새로 만들어서 거기에 액세스 할 수 있는지 확인합니다. 또한, 당신이 그것을 사용할 수 없다고 말할 때 ... 오류가 무엇입니까? 어떤 오류도 볼 수 없습니다. – Arran

+2

'stopWatch' 필드를 잘못 선언했습니다. 선언 유형을 잊어 버렸습니다. :) 편집 : C#을 구문/Intellisense 검사기 때문에 그것 때문에 너트 갔다. –

답변

8

당신이 무엇을 필요가있다 :

Stopwatch stopWatch = new Stopwatch(); 

당신은 단지이 C# 개체를 만드는 방법하지 않습니다 (public stopWatch = new StopWatch).

stopWatch이 인스턴스 인 경우 StopWatch이 클래스 정의입니다.

관련 문제