English 中文(简体)
以匿名方式捕获物体的性能影响如何?
原标题:What is the performance impact of capturing objects in an anonymous method?
  • 时间:2010-05-06 15:38:23
  •  标签:
  • c#
  • .net

在多面应用中,撰写诸如以下内容的著作的效绩效果如何:

TestClass t = new TestClass();
ThreadPool.QueueUserWorkItem(x=>DoSomething(t));

如果这样写的话,会有什么区别:

TestClass t = new TestClass();
ThreadPool.QueueUserWorkItem(x=>{
                                   TestClass t2 = x as TestClass;
                                   DoSomething(t2);

                                }, t);

在研究时,如何做到:

  TestClass t = new TestClass();
  Action<TestClass> someAction = DoSomething;
  someAction.BeginInvoke(t, asyncResult=>{
                                             Action<TestClass> a = asyncResult.State as Action<TestClass>;
                                             a.EndInvoke(asyncResult);
                                         }, someAction);

在一个有些相关的问题中,所有这些问题在一生中究竟是多少?

问题回答

TEST IT! 几个快速基准应该给你答案。

我猜测这一差异可能太小,除非你进行数千次行动,但你可以肯定。





相关问题
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. ...

热门标签