Forum Discussion

Dominic_Dinh's avatar
Dominic_Dinh
Icon for Nimbostratus rankNimbostratus
Aug 15, 2019

How to Create a empty pool using C#?

I wrote following code to create a LBPool but it only works if i have at least one member(s). My application need to create a empty pool and add it to a VirtualServer.

 

// Create member

        var members = nodes.Select(t => new CommonIPPortDefinition

        {

          address = t.Address,

          port = t.Port

        }).ToArray();

        

        var newMembers = new CommonIPPortDefinition[][] { members };

 

        // Create pool with algorithms

        m_interfaces.LocalLBPool.create(new string[] { name }, new LocalLBLBMethod[] { method }, newMembers);

 

  •  

    Steps to Create Thread Pooling in C#.NET

     

     

    static void ProcessWithThreadMethod()

    {

       for (int i = 0; i <= 10; i++)

     {

        Thread obj = new Thread(Process);

        obj.Start();

     }

    }

     

     

    static void ProcessWithThreadPoolMethod()

    {

       for (int i = 0; i <= 10; i++)

     {

        ThreadPool.QueueUserWorkItem(new WaitCallback(Process));

     }

    }

     

     

    using System;

    using System.Threading;

    using System.Diagnostics;

     

    namespace ThreadPooling

    {

       class Program

      {

        static void Main(string[] args)

        {

     

           

          Stopwatch mywatch = new Stopwatch();

     

          Console.WriteLine("Thread Pool Execution");

     

          mywatch.Start();

          ProcessWithThreadPoolMethod();

          mywatch.Stop();

     

          Console.WriteLine("Time consumed by ProcessWithThreadPoolMethod is : " + mywatch.ElapsedTicks.ToString());

          mywatch.Reset();

     

     

          Console.WriteLine("Thread Execution");

     

          mywatch.Start();

          ProcessWithThreadMethod();

          mywatch.Stop();