简体   繁体   中英

C# completely loading a WinForm without showing it (VS2010)

Working with DevExpress 2012 vol 2.10 C# on top of VS 2010

First question seems to have been unclear... So lets clear it a bit (or try to at least)!

We are building a MainForm with a Ribbon containing many buttons. Every button in the Ribbon is disabled until their respective state is "ready to enable". "ready to enable" depends on one thing : The WinForm_Popup associated with the button has been completely built, including data retrieval and DevExpress.ExpressApp.ListView construction.

  1. Retrieving data from database takes less than 0.1 second
  2. Calling the WinForm_Popup.Show() takles over 15 seconds

We tried to put this in a Thread or a Task, with no success: It crashes on WinForm_Popup.Show() with an exception related to the DragDrop Event.

What I know by now, is Show() method takes long, but I don't have a clue what happens in this method, but constructing the DevExpress.ExpressApp.ListView, which should be taken away from Show (or do it in a Task or Thred maybe).

Or, in other words, having the WinForm_Popup UI completely built as when it's shown but doing this asynchronously (like in a separate Task, for example).

Any idea, advice, help, link, suggestion, tip... Any "thing" ?

Make a new form and make it empty. In the program.cs file change your main form to the new form. Then make the new form constructor be like this:

public newForm()
        {
            this.Hide();
            Thread backTh = new Thread(() =>
                {
                    MainForm mf = new MainForm();
                    mf.Show();
                });
            backTh.Start();
        }

I would go for the opposite approach, one that is usually used in slow loading systems like a web browser. Why don't you load the form fast, then use a thread to populate your slow loading grid view?

That way, you can have like a spinning hourglass (or something less 1995) that will tell your users that the data is loading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM