How do I show a “Loading . . . please wait” message in Winforms for a long loading form?

前端 未结 12 617
一生所求
一生所求 2020-12-04 17:29

I have a form that is very slow because there are many controls placed on the form.

As a result the form takes a long time to loaded.

How do I load the fo

12条回答
  •  执笔经年
    2020-12-04 18:23

    Well i do it some thing like this.

            NormalWaitDialog/*your wait form*/ _frmWaitDialog = null;
    
    
            //Btn Load Click Event
            _frmWaitDialog = new NormalWaitDialog();
            _frmWaitDialog.Shown += async (s, ee) =>
            {
                await Task.Run(() =>
               {
                   // DO YOUR STUFF HERE 
    
                   //Made long running loop to imitate lengthy process
                   int x = 0;
                   for (int i = 0; i < int.MaxValue; i++)
                   {
                       x += i;
                   }
    
               }).ConfigureAwait(true);
                _frmWaitDialog.Close();
            };
            _frmWaitDialog.ShowDialog(this);
    

提交回复
热议问题