Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Threading paradigms available under the .NET CLR, using C#

, 23 Dec 2004
This article discusses the various threading paradigms available under the .NET CLR, using C#.
managedthreadcs-async.zip
ManagedThreadCS-Async.sln.old
App.ico
ManagedThreadCS-Async.csproj.user
managedthreadcs-pool.zip
App.ico
ManagedThreadCS-Pool.csproj.user
managedthreadcs-pool2.zip
App.ico
ManagedThreadCS-Pool.csproj.user
managedthreadcs.zip
App.ico
ManagedThreadCS.csproj.user
using System;
using System.Collections;

namespace ManagedThreadCS
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class CMain
	{
  [STAThread]
		static void Main(string[] args)
		{
		 // build a test list of identifiers
 	 ArrayList list ;
   list = BuildDefaultList();
   //list = BuildLargeList();
   Console.WriteLine("List size = {0}", list.Count);

   Console.WriteLine("START");
   int startLoop = Environment.TickCount;
   
   const int MAXCNT = 1;
   for (int x=0; x < MAXCNT; x++)
   {
    int start = Environment.TickCount;
    
    // create manager responsible for proportioning out the work to be done
    // as well as monitoring for its completion
    CGSRMgr mgr = new CGSRMgr();

	   // wire up event handler in order to get notification of task completion
	   mgr.Notify += new CGSRMgrEventHandler(MgrNotify);
	   
    // provide list of tasks for the manager
    mgr.SetObligorList(list);
    
    // perform task
    mgr.ProcessObligorList();
    
    // wait for manager to complete the assigned tasks
    mgr.GetMRE().WaitOne();
    
    int end = Environment.TickCount;
    int gsrCount = mgr.GetTotalGSRCount();
    Console.WriteLine ("Total number of GSR records processed = {0}",gsrCount);
    Console.WriteLine ("Total elapse time = {0} ms", end - start);
    mgr.StreamToFile("csDumpGSR.txt");
   }
   int endLoop = Environment.TickCount;
   Console.WriteLine ("Total average time = {0} ms", (endLoop - startLoop)/MAXCNT);
      
   Console.WriteLine("COMPLETE!!");
   return;	     
		}
		
  static void MgrNotify(object sender, EventArgs e)
  {
   Console.WriteLine("EVENT NOTIFICATION RECEIVED");
  }
		
  static ArrayList BuildDefaultList()
  {
   const int LISTSIZE = 15;
   ArrayList list = new ArrayList(LISTSIZE);

   int i = 1;
   int k = 10;
   for (int j=1; j<=LISTSIZE; j++)
   {
    if (i % 5 == 0)
    {
     list.Add(i*k);
     i=1;
     k *= 10;
    }
    else
    {
     list.Add(i*k);
     ++i;
    }
   }
   return list;
  }

  static ArrayList BuildLargeList()
  {
   const int LISTSIZE = 250;
   ArrayList list = new ArrayList(LISTSIZE);

   for (int j=1; j<=LISTSIZE; j++)
     list.Add(j*10);

   return list;
  }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Gary J. Kuehn
Engineer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 23 Dec 2004
Article Copyright 2004 by Gary J. Kuehn
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid