Consider this scenario: I have two forms (Form1 and Form2). When a button is clicked in Form1, it loads Form2. Form2 contains开发者_Python百科 gridcontrol to show some data. Since the data is large, Form2 takes some time to load. That freezes the whole application.
I would like to access Form1 while Form2 is loading. Is it possible?
You could use a BackgroundWorker to load the data in a separate thread to avoid blocking the main thread.
Yes it is if you load your data in Form2 in a different thread. You can check this page.
Look at this answer for Loading data from DB asynchronously in win forms
.
You will have to load data asynchronously to allow form2's UI responsive.
Now to access Form1 from Form2, you could:
- Pass form1's reference to form2 (not recommended)
- Create a static class with global members to exchange data.
精彩评论