避免在ui线程执行Parallel更新ui,否则会导致ui deadlocks

                Parallel.ForEach(source, new ParallelOptions
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount,
                    CancellationToken = CancellationToken.Token
                }, item =>
                {
                    //里面下载图片,更新到ui
                    DownImage(item);
                });

上面代码会导致ui deadlocks,需要如下图代码避免在ui线程执行parallel

Task.Run(() =>
            {
                Parallel.ForEach(source, new ParallelOptions
                {
                    MaxDegreeOfParallelism = Environment.ProcessorCount,
                    CancellationToken = CancellationToken.Token
                }, item =>
                {
                    //里面下载图片,更新到ui
                    DownImage(item);
                });
            });

 

上一篇:消除11.2上的db file parallel read


下一篇:消除11.2上的db file parallel read