简体   繁体   中英

Dialog from BackgroundWorker waiting for user input

Can I open Dialog from BackgroundWorker and pause it until user decides?

MyWorker = new System.ComponentModel.BackgroundWorker();
MyWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(CopyWorker_DoWork);
MyWorker.RunWorkerAsync();

private void MyWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    int i=0;
    while ((i) < collection.Count())
    {
       cListEntry item = collection[i];
       if (item.conflicted ==true) {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                var dialog = new WindowConflict();
                //Open dialog and wait for user action
                if (dialog.ShowDialog() == true)
                {
                    item.level = dialog.Response;
                } 

您应该使用invoke而不是begininvoke,begininvoke允许任务继续运行,但您希望它等待。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM