开发者

Winforms database connection in form_load

开发者 https://www.devze.com 2023-03-07 19:13 出处:网络
I\'m not posting any code here, because the question is more general.So I need 开发者_高级运维to populate datagrid with values by calling table adapter\'s methods (2 tier app).Usually I do that in for

I'm not posting any code here, because the question is more general. So I need 开发者_高级运维to populate datagrid with values by calling table adapter's methods (2 tier app). Usually I do that in form load event. Since recently though, database server becomes unavailable which results in a hanging form. That's nasty. Could you share some common scenarios you use to avoid that? May be I should rather do that in Shown event? And yet better do it asynchronously, say with a backgroundworker?


I do in this way:
- I disable datagrids and show some message in a StatusBar
- In Shown event I start a BackgroundWorker that loads from db and fills datasets
- When worker completes its job I enable datagrids...

In this way your form can handle user inputs without hanging or having refresh problems...

0

精彩评论

暂无评论...
验证码 换一张
取 消