由於@IkramTurgunbaev說你需要異步加載數據並更新狀態欄。在你打電話給你getAlertGrid方法的地方做這樣的事情:
private void MethodThatCallsGetAlertGrid()
{
// Show the progress bar and set the style of progress bar to Marquee. This will show continiously scrolling block across progress bar, as you cannot know the current progress percent
this.progressBar1.Visible = true;
this.progressBar1.Style = ProgressBarStyle.Marquee;
// Start loading the data source async
Task.Factory.StartNew(() =>
this.getAlertGrid())
.ContinueWith((antecedent) =>
{
// Set data source on UI thread. Remove the same row from your getAlertGrid method
ugAlert.DataSource = dtAlert;
// Hide the progress bar
this.progressBar1.Visible = false;
}, TaskScheduler.FromCurrentSynchronizationContext());
使用'Backgroundworker'或'Thread' –
@IkramTurgunbaev嗨。關於任務呢? –
是的,你也可以使用任務 –