728x90
반응형
728x170
▶ 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 클래스 : PushFrame 메소드를 사용해 UI 업데이트 하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBox Name="textBox1"
Width="100"
Height="25"
HorizontalContentAlignment="Right"
VerticalContentAlignment="Center" />
<Button Name="runButton"
Margin="0 10 0 0"
Width="100"
Height="30"
Content="실행" />
</StackPanel>
</Grid>
</Window>
728x90
▶ 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.runButton.Click += runButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 실행 버튼 클릭시 처리하기 - runButton_Click(sender, e)
/// <summary>
/// 실행 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void runButton_Click(object sender, RoutedEventArgs e)
{
try
{
this.runButton.IsEnabled = false;
for(int i = 0; i < 100; i++)
{
this.textBox1.Text = i.ToString();
DoEvents();
Thread.Sleep(10);
}
}
finally
{
this.runButton.IsEnabled = true;
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 프레임 종료하기 - ExitFrame(frame)
/// <summary>
/// 프레임 종료하기
/// </summary>
/// <param name="frame">프레임</param>
/// <returns>처리 결과</returns>
private object ExitFrame(object frame)
{
((DispatcherFrame)frame).Continue = false;
return null;
}
#endregion
#region 이벤트 실행하기 - DoEvents()
/// <summary>
/// 이벤트 실행하기
/// </summary>
private void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke
(
DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame),
frame
);
Dispatcher.PushFrame(frame);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 비동기 가상화 컬렉션 사용하기 (0) | 2021.05.21 |
---|---|
[C#/WPF] PathGeometry 클래스 : GraphicsPath 객체에서 패스 지오메트리 구하기 (0) | 2021.05.13 |
[C#/WPF] 누겟 설치 : AvalonEdit (0) | 2021.05.10 |
[C#/WPF] 코드 편집기(Code Editor) 사용하기 (0) | 2021.05.07 |
[C#/WPF] Dispatcher 클래스 : DisableProcessing 메소드를 사용해 디스패처 비활성하기 (0) | 2021.05.01 |
[C#/WPF] Dispatcher 클래스 : BeginInvoke 메소드 사용하기 (0) | 2021.04.30 |
[C#/WPF] ScrollViewer 클래스 : 애니메이션 스크롤 뷰어 사용하기 (0) | 2021.04.28 |
[C#/WPF] UWP API 사용하기 (0) | 2021.04.26 |
[C#/WPF] TOTP(Time-based One-Time Password) 사용하기 (0) | 2021.04.26 |
[C#/WPF] Dispatcher 클래스 : Invoke 메소드를 사용해 UI 업데이트 하기 (0) | 2021.04.22 |
댓글을 달아 주세요