Winforms database connection in form_load
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...
精彩评论