내 wpf 응용 프로그램에서 별도의 스레드로 버튼 클릭 이벤트를 만들고 UI가 사용자에게 반응하도록 백그라운드 프로세스로 실행했습니다. 아래 코드, 내가 별도의 window.For 나는 아래 디스패처 방법을 사용하고이 작업 사용자에게 제공하고 파일 이름을 변경하는 옵션을 가지고있는 WorkerMethod에와Dispatcher.BeginInvoke C#
private void btn_convert_Click(object sender, RoutedEventArgs e)
{
//Makes the conversion process as background task which
//makes the UI responsive to the user.
Thread thread = new Thread(new ThreadStart(WorkerMethod));
thread.SetApartmentState(ApartmentState.MTA);
thread.IsBackground = true;
thread.Start();
}
,
if (MessageBox.Show("Do you want to set filename?",
"Information", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) ==
MessageBoxResult.Yes)
{
Action showOutput =() =>
{
BlueBeamConversion.SetOutput _setOutput =
new BlueBeamConversion.SetOutput();
_setOutput.ShowDialog();
};
Dispatcher.BeginInvoke(showOutput);
if (String.IsNullOrEmpty(MainWindow.destinationFileName))
return;
여기서 destinationFileName은 SetOutput 창에서 설정됩니다. 이제 코드를 실행하면 SetOutput 창이 나타나고 파일 이름을 설정할 때까지 기다리지 않습니다. 내가 window.Any의 suggessions은 대부분 환영의 setOutput에서 확인 버튼을 클릭 때까지 아래의 코드로 제공되는 파일 이름,
if (String.IsNullOrEmpty(MainWindow.destinationFileName))
return;
을 설정하기 전에 내가 어떻게 보유 할 수 있습니다.
BeginInvoke 대신 dispatcher.Invoke를 사용했습니다. 이제 창을 쥐고 새 이름을 얻습니다. 특정 라인에 workmethod의 코드를 계속되면하지만, 제발 벌금 코드 bekow,
if (MessageBox.Show("Do you want to set filename?", "Information", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
{
Action showOutput =() =>
{ BlueBeamConversion.SetOutput _setOutput = new BlueBeamConversion.SetOutput(); _setOutput.ShowDialog(); };
Dispatcher.Invoke(showOutput);
for (int i = 0; i < _listFiles.Items.Count; i++)--- here it exits
{--------- }
감사 상 기사 응용 프로그램 자체 종료
문제에 대한 (부분) 해결책을 편집하지 마십시오. 'ShowDialog()'가 아닌'Show()'라는 원래 코드 –
그리고 _listFiles은 무엇입니까? 또한 : 가독성을 위해 포맷을 시도하십시오. –
_listFiles는 이름 listview 컨트롤입니다. 찾아보기 및 파일을 listview에 추가. – Sangeetha