■ Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기
------------------------------------------------------------------------------------------------------------------------
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <Button Name="button" Width="150" Height="50" FontSize="20" FontWeight="Bold" Content="테스트" /> </Grid> </Window>
|
▶ MainWindow.xaml.cs
using System.Threading; using System.Windows; using System.Windows.Threading;
namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent();
this.button.Click += button_Click; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private
#region 버튼 클릭시 처리하기 - button_Click(sender, e)
/// <summary> /// 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void button_Click(object sender, RoutedEventArgs e) { this.button.IsEnabled = false;
Dispatcher.Invoke((ThreadStart)(() => { }), DispatcherPriority.ApplicationIdle);
Thread.Sleep(5000);
Dispatcher.Invoke((ThreadStart)(() => { }), DispatcherPriority.ApplicationIdle);
this.button.IsEnabled = true; }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
'C# > WPF' 카테고리의 다른 글
[C#/WPF] TreeView 클래스 : ItemContainerGenerator 속성을 사용해 바인딩 데이터의 트리 노드 구하기 (0) | 2019.06.02 |
---|---|
[C#/WPF] ComponentDispatcher 클래스 : ThreadFilterMessage 정적 이벤트를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] HwndSource 클래스 : AddHook 메소드를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] Dispatcher 클래스 : UnhandledException 이벤트를 사용해 예외 처리하기 (0) | 2019.06.02 |
[C#/WPF] SystemColors 클래스 : 시스템 색상 표시하기 (0) | 2019.06.02 |
[C#/WPF] Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기 (0) | 2019.05.30 |
[C#/WPF] 메모리 손실이 없는 비트맵 소스 구하기 (0) | 2019.05.30 |
[C#/WPF] AppDomain 클래스 : 동일 프로세스에서 멀티 WPF 애플리케이션 실행하기 (0) | 2019.05.30 |
[C#/WPF] 다중 UI 스레드 윈도우 사용하기 (0) | 2019.05.30 |
[C#/WPF] ScrollViewer 클래스 : 마우스를 사용해 스크롤하기 (0) | 2019.05.28 |
[C#/WPF] BitmapImage 클래스 : 웹에서 비트맵 이미지 구하기 (0) | 2019.05.27 |
댓글을 달아 주세요