Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET

Connection Pooling in multithreaded applications

Rate me:
Please Sign up or sign in to vote.
3.29/5 (8 votes)
1 Mar 2010CPOL3 min read 89.7K   3.3K   24  
Approaches describing a design to handle connection objects and pools in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ProjectBusiness;

namespace ConsoleForMultiConnectionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Operation started.");

            try
            {
                for (int index = 0; index < 100; index++)
                {

                    Thread statusUpdateThread = new Thread(new ThreadStart(RunOnThread));
                    statusUpdateThread.IsBackground = true;
                    statusUpdateThread.Start();

                }

            }
            catch (System.InvalidOperationException invalidOperatioExcpetion)
            {
                throw;
            }
            catch (System.Data.SqlClient.SqlException sqlException)
            {
                throw;
            }
            catch
            {
                throw;
            }

            Console.WriteLine("Operation completed... Press <Enter> to exit.");
            Console.ReadLine();
        }

        
        private static void RunOnThread()
        {
            Project SomeProject = new Project() { Name = "SomeProject" };

            List<Employee> employees = new List<Employee>()
         {
            new Employee(){Name ="A"},
            new Employee(){Name ="B"},
            new Employee(){Name ="C"},
            new Employee(){Name ="D"},
            new Employee(){Name ="E"}
         };

            employees.ForEach(e => e.AddProject(SomeProject));

            SomeProject.UpdateStatus();

        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions