English 中文(简体)
平行使用。 校对
原标题:Using Parallel.Foreach Inside A Thread
  • 时间:2012-04-12 21:01:22
  •  标签:
  • c#
  • .net
  • linq

在服务开始时,我有装满数据线。 我称之为一种同时使用的方法。 收集一套数据。 但是,我在平行旁边的旁观中发现的气味道,没有发现假象。

*。 如果我消除了这种平行,同样的逻辑就发挥了作用。 穿透或穿透镜。 * 标明名单有帮助>。

    loadingThread = new Thread(new ThreadStart(PreloadData));
                loadingThread.IsBackground = true;
                loadingThread.Start();
---------------------------------------

    public static void PreloadData()
    {
     Parallel.ForEach(loadedIDs.Keys, indexDefId =>
                    {
                        List<FixingEvent> lst = null;
                        lock (loadedEvents)
                        {
                            lst = (from e in loadedEvents where e.DIVACode.Equals(indexDefId) select e).ToList();
                        }

---------------------------
    }

在Le 内部的Llinq 查询中,我有一个例外,因此物体参考资料错误

感谢任何帮助。

最佳回答

I guess the list loadedEvents contains null elements. Maybe due to a race condition.

问题回答

页: 1 http://msdn.microsoft.com/en-us/library/c5kehkcz%28v=vs.80%29.aspx”rel=“nofollow”>msdn :

Best practice is to define a private object to lock on, or a private static object variable to protect data common to all instances.

你们不需要锁定你们正在接触的物体——你只需要一个物体。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...