첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 오버레이 폼 헬퍼 1
        /// </summary>
        private OverlayFormHelper helper1 = null;

        /// <summary>
        /// 오버레이 폼 헬퍼 2
        /// </summary>
        private OverlayFormHelper helper2 = null;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            FormClosing        += Form_FormClosing;
            this.button1.Click += button1_Click;
            this.button2.Click += button2_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼을 닫을 경우 처리하기 - Form_FormClosing(sender, e)

        /// <summary>
        /// 폼을 닫을 경우 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.helper1?.Close();

            this.helper1 = null;

            this.helper2?.Close();

            this.helper2 = null;
        }

        #endregion
        #region 버튼 1 클릭시 처리하기 - button1_Click(sender, e)

        /// <summary>
        /// 버튼 1 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private async void button1_Click(object sender, EventArgs e)
        {
            this.helper1 = new OverlayFormHelper(this.panelControl1, OverlayFormHelper.DefaultFont12, Color.Black, true, -30, 0);

            try
            {
                this.helper1.Show();

                this.helper1.SetMessage("작업 1 처리중...");

                await Task.Run
                (
                    async () => { await Task.Delay(5000, this.helper1.CancellationTokenSource.Token); },
                    this.helper1.CancellationTokenSource.Token
                );
            }
            catch(Exception exception)
            {
                if(exception is TaskCanceledException)
                {
                    XtraMessageBox.Show(this, "작업 1이 취소되었습니다.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                }
            }
            finally
            {
                this.helper1?.Close();

                this.helper1 = null;
            }
        }

        #endregion
        #region 버튼 2 클릭시 처리하기 - button2_Click(sender, e)

        /// <summary>
        /// 버튼 2 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private async void button2_Click(object sender, EventArgs e)
        {
            this.helper2 = new OverlayFormHelper(this.panelControl2, OverlayFormHelper.DefaultFont12, Color.Black, true, -30, 0);

            try
            {
                this.helper2.Show();

                this.helper2.SetMessage("작업 2 처리중...");

                await Task.Run
                (
                    async () => { await Task.Delay(5000, this.helper2.CancellationTokenSource.Token); },
                    this.helper2.CancellationTokenSource.Token
                );
            }
            catch(Exception exception)
            {
                if(exception is TaskCanceledException)
                {
                    XtraMessageBox.Show(this, "작업 2가 취소되었습니다.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                }
            }
            finally
            {
                this.helper2?.Close();

                this.helper2 = null;
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형
Posted by 사용자 icodebroker

댓글을 달아 주세요