출처 : http://stackoverflow.com/questions/9770771/c-sharp-thread-and-a-waiting-form#9773081



using System;

using System.Threading;

using System.Windows.Forms;

 

public partial class LoadingForm : Form

{

    //http://stackoverflow.com/questions/9770771/c-sharp-thread-and-a-waiting-form#9773081

    public Action Function { get; set; }

 

    public LoadingForm()

    {

        InitializeComponent();

        this.Shown += new EventHandler(Form_Loaded);

 

    }

    private void Form_Loaded(object sender, EventArgs e)

    {

        var thread = new Thread(

            () =>

            {

                Function?.Invoke();

                this.Invoke(

                    (Action)(() =>

                    {

                        this.Close();

                    }));

            });

        thread.Start();

    }

}

 


해당 폼의 화면에는 loding gif 파일을 하나 넣어둔다.


사용 방법은 아래와 같다.



LoadingForm f = new LoadingForm();

f.Function = (() => { Console.WriteLine("테스트 출력!"); });

f.CenterParent(this).ShowDialog();





























Posted by motolies
,