wpf 응용 프로그램에서 - UI가 버튼 클릭으로 고정되고 - 거대한 데이터 처리 중에 통화 중 표시기를 표시하는 방법?긴 프로세스가 실행되는 동안 사용중 표시기를 표시하는 방법은 무엇입니까?
나는 배경 작업자 프로세스를 시도했지만 그 예외를 던지고있다.
메시지에서 "호출 스레드가"당신의 UI 스레드가 아닌...
샘플 코드 :
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle);
BackgroundWorker worker = sender as BackgroundWorker;
this.busyIndicator.Visibility = Visibility.Visible;
busyIndicator.IsBusy = true;
for (int k = 1; (k <= 10); k++)
{
if ((worker.CancellationPending == true))
{
e.Cancel = true;
break;
}
else
{
int intAutomationID = 0;
int intAutomation_SS_ID = 0;
int intAS_ID = 0;
string strProcedureName = "";
//busyIndicator.Visibility = Visibility.Visible;
try
{
// Insert entry into AUTOMATION_PROCESS table.
intAutomationID = Pkg_TargetsIdentifiers.InsertAutomationProcess(Convert.ToInt32(cmbIdentifier.SelectedValue),
Convert.ToInt32(cmbSourceData.SelectedValue), "InProgress", 0, "Insert");
if (intAutomationID > 0)
{
for (int i = 0; i <= dgvProcessLists.Items.Count - 1; i++)
{
int j = 3;
strProcedureName = "";
strProcedureName = (dgvProcessLists.Items[i] as DataRowView).Row.ItemArray[j].ToString();
if (!string.IsNullOrEmpty(strProcedureName))
{
//AS_ID
// InitializeMouseHandlersForVisual(dgvProcessLists);
intAS_ID = Convert.ToInt32((dgvProcessLists.Items[i] as DataRowView).Row.ItemArray[0].ToString());
intAutomation_SS_ID = Pkg_TargetsIdentifiers.InsertAutomationStepsStatus(intAS_ID, intAutomationID,
"Inprogress", 0, "Insert");
bool boolStatus = Pkg_TargetsIdentifiers.CallActionProcess(strProcedureName, intAutomationID);
if (boolStatus == true)
{
//var selectedRow = DataProcessing.Class1.GetSelectedRow(this.dgvProcessLists);
//var columnCell = DataProcessing.Class1.GetRow(this.dgvProcessLists,0);
intAutomation_SS_ID = Pkg_TargetsIdentifiers.InsertAutomationStepsStatus(intAS_ID, intAutomationID,
"Completed", intAutomation_SS_ID, "Update");
intAS_ID = 0;
strProcedureName = "";
DataRowView row = (dgvProcessLists.Items[i] as DataRowView);
if (row != null)
{
if (row.DataView.Table.Columns.Contains("Status"))
{
Type type = row["Status"].GetType();
string status = row["Status"] == System.DBNull.Value ? null : (string)row["Status"];
if (boolStatus == true)
{
Uri uri = new Uri("pack://application:,,,/Images/green.jpg");
BitmapImage source = new BitmapImage(uri);
}
if (boolStatus == false)
{
Uri uri = new Uri("pack://application:,,,/Images/red.jpg");
BitmapImage source = new BitmapImage(uri);
}
}
}
continue;
}
else
{
break;
}
}
}
intAutomationID = Pkg_TargetsIdentifiers.InsertAutomationProcess(Convert.ToInt32(cmbIdentifier.SelectedValue),
Convert.ToInt32(cmbSourceData.SelectedValue), "Completed", intAutomationID, "Update");
}
// Perform a time consuming operation and report progress.
System.Threading.Thread.Sleep(500);
worker.ReportProgress((k * 10));
}
catch (Exception ex)
{
throw ex;
}
finally
{ }
}
}
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle);
if ((e.Cancelled == true))
{
this.busyIndicator.Visibility = Visibility.Hidden;
busyIndicator.IsBusy = false;
}
else if (!(e.Error == null))
{
this.busyIndicator.Visibility = Visibility.Hidden;
busyIndicator.IsBusy = false;
}
else
{
this.busyIndicator.Visibility = Visibility.Hidden;
busyIndicator.IsBusy = false;
}
}
private void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
this.busyIndicator.Visibility = Visibility.Visible;
busyIndicator.IsBusy = true;
}
/// <summary>
/// btnStartProcess_Click
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStartProcess_Click(object sender, RoutedEventArgs e)
{
try
{
if (bw.IsBusy != true)
{
bw.RunWorkerAsync();
}
//worker.RunWorkerAsync();
// //};
// //worker.RunWorkerCompleted += (o, ea) =>
// //{
// // busyIndicator.Visibility = Visibility.Hidden;
// // busyIndicator.IsBusy = false;
// //};
// //worker.RunWorkerAsync();
// //};
// //worker.RunWorkerAsync();
//bw.RunWorkerCompleted += (o, ea) =>
//{
// busyIndicator.IsBusy = false;
// busyIndicator.Visibility = Visibility.Hidden;
//};
//busyIndicator.IsBusy = true;
//busyIndicator.Visibility = Visibility.Visible;
//bw.RunWorkerAsync();
}
catch (Exception ex)
{
throw ex;
}
}
이 필요한 작업을 수행하십시오 ..
감사와 안부, 비제이 Babu
이 몇 가지 코드를 표시하고 문제 – Nitin