Silverlight/Migration from 1.1

HtmlTimer 대신 뭘 쓰면 될까요?

길버트리 2008. 3. 6. 21:06
Silverlight 2에서 HtmlTimer가 사라졌습니다.

System.Threading.Timer도 있고 System.Windows.Threading.DispatcherTimer도 있는데
이제 무얼 쓸까요?

HtmlTimer를 쓰시던 분은 DispatcherTimer를 사용하실 것을 권합니다.
사용방법이 똑같아서 변수 선언부만 찾아서 고치시고, Interval을 TimeSpan으로 수정하시면
컴파일 에러가 해결될 거예요.

DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(3000); // 3초
timer.Tick += new EventHandler(timer_Tick);
timer.Start();

HtmlTimer에는 아래와 같이 Obsolete가 선언되어 있어서 ,
컴파일 할 때마다 경고 뜨는게 보기 싫으셨죠?

[Obsolete("This is not a high resolution timer and is not suitable for short-interval animations. A new timer type will be available in a future release.")]
public class HtmlTimer : IDisposable

이제 경고 받으시지 않으셔도 됩니다. ^^

'Silverlight > Migration from 1.1' 카테고리의 다른 글

Downloader 대신 WebClient  (1) 2008.03.08
Image.Source는 어떻게 쓰나  (0) 2008.03.06
BrowserHost야 어딜 간거니???  (4) 2008.03.06