Tag: 并行处理

并行不适用于Entity Framework

我有一个ID列表,我需要在每个ID上运行几个存储过程。 当我使用标准的foreach循环时,它工作正常,但是当我有很多记录时,它的工作速度很慢。 我想将代码转换为与EF一起使用,但我得到一个例外:“底层提供程序在Open上失败”。 我在Parallel.ForEach中使用此代码: using (XmlEntities osContext = new XmlEntities()) { //The code } 但它仍然抛出exception。 任何想法我如何使用与EF并行? 我是否需要为我正在运行的每个程序创建一个新的上下文? 我有大约10个程序,所以我认为创建10个上下文非常糟糕,每个上下文一个。

为什么Parallel.ForEach比AsParallel()快得多.ForAll()尽管MSDN建议不然?

我一直在做一些调查,看看我们如何创建一个贯穿树的multithreading应用程序。 为了找到如何以最佳方式实现这一点,我创建了一个运行在我的C:\ disk中的测试应用程序并打开所有目录。 class Program { static void Main(string[] args) { //var startDirectory = @”C:\The folder\RecursiveFolder”; var startDirectory = @”C:\”; var w = Stopwatch.StartNew(); ThisIsARecursiveFunction(startDirectory); Console.WriteLine(“Elapsed seconds: ” + w.Elapsed.TotalSeconds); Console.ReadKey(); } public static void ThisIsARecursiveFunction(String currentDirectory) { var lastBit = Path.GetFileName(currentDirectory); var depth = currentDirectory.Count(t => t == ‘\\’); //Console.WriteLine(depth + “: ” + […]

加速位图灰度转换,OpenMP是C#中的一个选项吗?

请帮助我使用openmp使这个代码并行这个代码是在按钮点击运行,文本框是128 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace IMG { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string path = “”; public void openimage() { if (openFileDialog1.ShowDialog() == DialogResult.OK) { path = openFileDialog1.FileName; Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); Bitmap curBitmap […]