Home arrow C# arrow Page 2 - IOCP Thread Pooling in C# - Part II

IOCP Thread Pooling in C# - Part II

In part 2, William will continue to explain how the create a class that will handle threads using a IOCP Thread Pool.

Author Info:
By: William Kennedy
Rating: 5 stars5 stars5 stars5 stars5 stars / 21
April 11, 2003
  1. · IOCP Thread Pooling in C# - Part II
  2. · The Sample Application
  3. · Review

print this article

IOCP Thread Pooling in C# - Part II - The Sample Application
(Page 2 of 3 )

Start by adding a new class to your C# project.  Remove all of the code provided by the Visual Studio .NET wizard.  Then add all of the following code.  In Main, an IOCP thread pool is created, and a single piece of work is posted to the IOCP thread pool.  We pass the data value of 10 along with the posted work. 

The main thread is then put to sleep. This gives the IOCP thread function time to wake up to process the work posted.  The last thing in main is to dispose the IOCP thread pool.  The IOCP thread function displays the value of the data passed into the IOCP thread pool.

using System;
using System.Threading;  // Included for the Thread.Sleep call
using Continuum.Threading;
namespace Sample
  /// <summary> Sample class for the threading class </summary>
  public class UtilThreadingSample
    /// <summary> Test Method </summary>
    static void Main()
      // Create the MSSQL IOCP Thread Pool
      IOCPThreadPool pThreadPool = new IOCPThreadPool(0, 5, 10, new IOCPThreadPool.USER_FUNCTION(IOCPThreadFunction));
    /// <summary> Function to be called by the IOCP thread pool.  Called when
    ///           a command is posted for processing by the SocketManager </summary>
    /// <param name="iValue"> The value provided by the thread posting the event </param>
    static public void IOCPThreadFunction(Int32 iValue)
        Console.WriteLine("Value: {0}", iValue);
      catch (Exception pException)

This is what you should see when you run the sample application.  On your own change the main function to call the PostEvent method several times and see how the IOCP thread pool performs.

Next: Review >>

blog comments powered by Disqus

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials