When I was looking at VS.NET 2003 / MSDN docn when pondering this question, I noticed 
that there is no mention of Delegate.BeginInvoke or Delegate.EndInvoke (nor of those 
methods for MulticastDelegate) when looking at the docn for the Delegate class.

Typing BeginInvoke on the "Index" tab gets you to "BeginInvoke method" -- that results 
in references to 5 classes that have a BeginInvoke method -- none of which are 
Delegate.

There are examples of how to use the various "asynch call patterns" involving 
Delegate.BeginInvoke, if you use the "Search" tab rather than the "Index" tab to look 
for BeginInvoke.

Is it easily explained why the docn for BeginInvoke and friends isn't part of the the 
docn for the Delegate class?

At 06:23 AM 3/11/2004, Richard Blewett wrote
>IIRC correctly the ThreadPool class is marginally faster although generally
>a bit less programmer friendly.
>
>And yes, they both queue work up to the CLR threadpool.
>
>Regards
>
>Richard Blewett
>DevelopMentor
>
>-----Original Message-----
>From: Moderated discussion of advanced .NET topics.
>[mailto:[EMAIL PROTECTED] On Behalf Of Sean Chase MCAD,
>MCSD
>Sent: 11 March 2004 02:19
>To: [EMAIL PROTECTED]
>Subject: [ADVANCED-DOTNET] BeginInvoke vs. ThreadPool.QueueUserWorkItem
>
>Am I comparing apples to oranges here? Other than the asynch callback with
>BeginInvoke, why would I use one over the other. Further, do both ways use
>threads from the thread pool?
>
>////////////////////////////
>///First Way
>///////////////////////////
>using System;
>using System.Collections;
>using System.Threading;
>using System.Diagnostics;
>
>class App {
>        [STAThread]
>        static void Main(string[] args) {
>                Utility u = new Utility();
>                ThreadPool.QueueUserWorkItem(new WaitCallback(u.GetPrimes),
>100000);
>                Console.Read();
>        }
>}
>
>class Utility {
>        public void GetPrimes(object objState) {
>                int max = (int) objState;
>                ArrayList list = new ArrayList();
>                BitArray flags = new BitArray(max + 1);
>                for (int i = 2; i <= max; i++) {
>                        if (!flags[i])
>                                for (int j = i * 2; j <= max; j += i)
>                                        flags[j] = true;
>                }
>                for(int i = 3; i < flags.Length; i++)
>                        if(!flags[i])
>                                list.Add(i);
>
>                if(list != null) {
>                        foreach(int i in list) {
>                                Console.WriteLine(i);
>                        }
>                }
>        }
>}
>
>////////////////////////////
>///Second Way
>///////////////////////////
>using System.Runtime.Remoting.Messaging;
>delegate ArrayList GetPrimesDelegate(int max);
>
>class App {
>        [STAThread]
>        static void Main(string[] args) {
>                Utility u = new Utility();
>                GetPrimesDelegate d = new GetPrimesDelegate(u.GetPrimes);
>                d.BeginInvoke(100000, new
>AsyncCallback(PrimesProcessed),null);
>                Console.Read();
>        }
>
>        static void PrimesProcessed(IAsyncResult ar) {
>                Debug.WriteLine("PrimesProcessed called...");
>                Debug.Flush();
>                AsyncResult aResult = (AsyncResult)ar;
>                GetPrimesDelegate temp =
>(GetPrimesDelegate)aResult.AsyncDelegate;
>                ArrayList list = temp.EndInvoke(ar);
>
>                if(list != null) {
>                        foreach(int i in list) {
>                                Console.WriteLine(i);
>                        }
>                }
>        }
>}
>
>class Utility {
>        public ArrayList GetPrimes(int max) {
>                ArrayList list = new ArrayList();
>                BitArray flags = new BitArray(max + 1);
>                for (int i = 2; i <= max; i++) {
>                        if (!flags[i])
>                                for (int j = i * 2; j <= max; j += i)
>                                        flags[j] = true;
>                }
>                for(int i = 3; i < flags.Length; i++)
>                        if(!flags[i])
>                                list.Add(i);
>                return list;
>        }
>}
>
>Can someone help me shine some light on this? Thanks!


J. Merrill / Analytical Software Corp

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to