나는 backgroundworker 문제가 있습니다. - 나는 스레딩에 익숙하지 않으므로 가능한 한 쉽게이 작업을 수행하려고합니다.C# backgroundworker advice
내 주된 문제는 최종 사용자가 .NET 4.0 만 지원하므로 await/async를 사용할 수 없으며 BGW가 내가 사용하는 프레임 워크에 가장 적합하다고 들었습니다.
DataGridview가 채워지는 동안로드하려는 GIF 애니메이션이있는 "기다려주십시오"양식이 있습니다. 어떻게 든 잠깐 기다려주십시오. "잠시만 기다려주십시오."라는 질문을 끝내기 위해 채워 넣었는지 확인해야합니다. 그러나 이것을 달성하는 방법에 조금 갇혀 있습니다.
public void btnSearch_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
Application.DoEvents();
try
{
this.TestDataTableAdapter.Fill(this.TesteDataData.TestDataTable, txtHotName.Text, ((System.DateTime)(System.Convert.ChangeType(txtDepartFrom.Text, typeof(System.DateTime)))), ((System.DateTime)(System.Convert.ChangeType(txtDepartTo.Text, typeof(System.DateTime)))), ((System.DateTime)(System.Convert.ChangeType(txtBookFrom.Text, typeof(System.DateTime)))), ((System.DateTime)(System.Convert.ChangeType(txtBookTo.Text, typeof(System.DateTime)))));
int RowC = TestDataTableDataGridView.RowCount;
if (RowC == 0)
{
MessageBox.Show(GlobVar.NoResults, "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
catch (System.Exception exc)
{
MessageBox.Show
(
"Problem" +
exc.Message, "An error has occured", MessageBoxButtons.OK, MessageBoxIcon.Warning
);
}
finally
{
//pleaseWait.Close();
}
내 DataGridView에 데이터를로드하는 버튼입니다. 그리고 지금까지이
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
pleaseWait.ShowDialog();
}
가 finally
인해 크로스 스레드로 작동하지 않습니다 내 DoWork 이벤트입니다 (그래서 현재 주석)하지만 난/루프를 수행 DataGridView에가 작성되어 있는지 확인하기 위해 확인 작업을 할 필요가 완료되면 DoWork
을 닫습니다. 또는 어떤 방법을 뛰어 다니면 RunWorkerCompleted
이되고 그 대신에 pleaseWait.Close();
을 넣을 수 있습니다.
제안 사항을 알려주십시오.
작업이 끝날 때 이벤트를 촬영하는 방법은 무엇입니까? –
'backgroundWorker1.DoWork'가 아니라 메인 ui 스레드에'pleaseWait' 대화 상자를 보여주고'backgroundWorker1'의'RunWorkerCompleted' 이벤트에 숨겨야합니다. 'this.TestDataTableAdapter.Fill' 부분은'backgroundWorker1.DoWork'에 들어가야 만합니다. – Pikoh