• <small id='mrSLG'></small><noframes id='mrSLG'>

      <bdo id='mrSLG'></bdo><ul id='mrSLG'></ul>

        <legend id='mrSLG'><style id='mrSLG'><dir id='mrSLG'><q id='mrSLG'></q></dir></style></legend>
        <i id='mrSLG'><tr id='mrSLG'><dt id='mrSLG'><q id='mrSLG'><span id='mrSLG'><b id='mrSLG'><form id='mrSLG'><ins id='mrSLG'></ins><ul id='mrSLG'></ul><sub id='mrSLG'></sub></form><legend id='mrSLG'></legend><bdo id='mrSLG'><pre id='mrSLG'><center id='mrSLG'></center></pre></bdo></b><th id='mrSLG'></th></span></q></dt></tr></i><div id='mrSLG'><tfoot id='mrSLG'></tfoot><dl id='mrSLG'><fieldset id='mrSLG'></fieldset></dl></div>
      1. <tfoot id='mrSLG'></tfoot>

        C# - ThreadPool QueueUserWorkItem 使用?

        C# - ThreadPool QueueUserWorkItem Use?(C# - ThreadPool QueueUserWorkItem 使用?)

        <small id='MIblO'></small><noframes id='MIblO'>

          <bdo id='MIblO'></bdo><ul id='MIblO'></ul>
        • <tfoot id='MIblO'></tfoot>
          • <legend id='MIblO'><style id='MIblO'><dir id='MIblO'><q id='MIblO'></q></dir></style></legend>
              <tbody id='MIblO'></tbody>

                  <i id='MIblO'><tr id='MIblO'><dt id='MIblO'><q id='MIblO'><span id='MIblO'><b id='MIblO'><form id='MIblO'><ins id='MIblO'></ins><ul id='MIblO'></ul><sub id='MIblO'></sub></form><legend id='MIblO'></legend><bdo id='MIblO'><pre id='MIblO'><center id='MIblO'></center></pre></bdo></b><th id='MIblO'></th></span></q></dt></tr></i><div id='MIblO'><tfoot id='MIblO'></tfoot><dl id='MIblO'><fieldset id='MIblO'></fieldset></dl></div>
                  本文介绍了C# - ThreadPool QueueUserWorkItem 使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  现在我正在使用以下代码添加排队线程.我不喜欢它.我的同事也不会,因为他们不太了解 C#.当然,我想要的只是将要在新线程中执行的方法排队.

                  Just right now I'm using following code to add queued threads. I don't like it. And my colleagues won't either because they don't know C# very well. All I want is of course to queue a method to be executed in a new thread.

                  private static void doStuff(string parameter)
                  {
                      // does stuff
                  }
                  
                  // call (a)
                  ThreadPool.QueueUserWorkItem(a => doStuff("hello world"));
                  // call (b)
                  ThreadPool.QueueUserWorkItem(delegate { doStuff("hello world"); });
                  

                  那么 ThreadPool.QueueUserWorkItem 还有其他使用变体吗?

                  So are there other use variations of ThreadPool.QueueUserWorkItem ?

                  最好是另一个 1-Line-Call.如果可能,请使用 Func<>Action<>.<小时>从答案和评论中得到 (b),我已经更喜欢它了.

                  Best would be another 1-Line-Call. If possible with use of Func<> or Action<>.


                  Got (b) from the answers and comments and I like it better already.

                  推荐答案

                  您的问题的答案取决于您如何设计应用程序.你把它放在一个共同的项目中吗?你不想开销一个简单的操作.

                  The answer for your question depends on how you design the application. Do you put it inside a common project ? you dont want to overhead a simple operations.

                  但是,您可以为接收参数、1 个参数、2 个参数等的 ThreadPool QueueUserItem 创建一个通用调用.这很好,而不是发送一个简单的字符串并受到限制.

                  But, You could create a generic call for ThreadPool QueueUserItem that receive params, 1 param, 2 param, etc.. This is good instead of sending a simple string and be restricted.

                  这就是你如何使用 WaitCallback 实现参数 QueueUserItem:

                  This how you impl a parameters QueueUserItem with WaitCallback:

                  ThreadPool.QueueUserWorkItem(
                    new WaitCallback(delegate(object state)
                    { YourMethod(Param1, Param2, Param3); }), null);
                  

                  取自 C# Execute Method (with Parameters) with ThreadPool

                  还有一些想法的链接:
                  http://msdn.microsoft.com/en-us/library/4yd16hza.aspx
                  .NET 中的通用线程池
                  delegate.BeginInvoke 和在 C# 中使用 ThreadPool 线程

                  And some links for ideas:
                  http://msdn.microsoft.com/en-us/library/4yd16hza.aspx
                  Generic ThreadPool in .NET
                  Difference between delegate.BeginInvoke and using ThreadPool threads in C#

                  这篇关于C# - ThreadPool QueueUserWorkItem 使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                • <legend id='IHWcb'><style id='IHWcb'><dir id='IHWcb'><q id='IHWcb'></q></dir></style></legend>

                        <i id='IHWcb'><tr id='IHWcb'><dt id='IHWcb'><q id='IHWcb'><span id='IHWcb'><b id='IHWcb'><form id='IHWcb'><ins id='IHWcb'></ins><ul id='IHWcb'></ul><sub id='IHWcb'></sub></form><legend id='IHWcb'></legend><bdo id='IHWcb'><pre id='IHWcb'><center id='IHWcb'></center></pre></bdo></b><th id='IHWcb'></th></span></q></dt></tr></i><div id='IHWcb'><tfoot id='IHWcb'></tfoot><dl id='IHWcb'><fieldset id='IHWcb'></fieldset></dl></div>

                        <tfoot id='IHWcb'></tfoot>

                            <bdo id='IHWcb'></bdo><ul id='IHWcb'></ul>

                            <small id='IHWcb'></small><noframes id='IHWcb'>

                              <tbody id='IHWcb'></tbody>