SIGN UP MEMBER LOGIN:    
ARTICLE

Recycler Introduction

Posted by Udit Dobhal Articles | .NET 4.5 February 20, 2012
This is test application which can be used to recycle the IIS Application Pools of the server.
Reader Level:
Download Files:
 

Introduction

This is a Test Application which can be used to recycle the IIS Application Pools of the server. In this application I have given only one server but you can give any number of servers you want just add the buttons and copy the code of the button "button_Server_Click" to the other button's code. Also you can add any number of application pools that you want to.

Using the code

This is a test application. In this application I have used WMIC Code to recycle the AppPools of the server. The code to recycle the AppPool is written in the button click event "button_Server_Click".

string command = String.Empty;//string variable..

//Passing WMIC code to command variable.For recycling more than one apppool declare multiple string variables and pass WMIC code like mentioned below.

command = "wmic /namespace:" + "\"\\\\root/MicrosoftIISv2\"" + " /node:" + " \"Your_Server_Name\"  " + "path IISApplicationPool where (name like '%Your_IISAppool1%') call recycle";
           ExecuteCmd cmd =
new ExecuteCmd();//declaring object of class ExecuteCmd
           cmd.ExecuteCommandAsync(command);
//Passing string variable containing WMIC code to method ExecuteCommandAsync declared in class ExecuteCmd.


//This"ExecuteCommandAsync" method is used  to execute the WMIC Command. it is in the class "ExecuteCmd"

public void ExecuteCommandAsync(string command)
        {
           
try
            {
               
//Asynchronously start the Thread to process the Execute command request.
                Thread objThread =
new Thread(new ParameterizedThreadStart(ExecuteCommandSync));
               
//Make the thread as background thread.
                objThread.IsBackground =
true;
               
//Set the Priority of the thread.
|                objThread.Priority = ThreadPriority.AboveNormal;

               //Start the thread.
                objThread.Start(command);

            }

            catch (ThreadStartException objException)
            {
               
// Log the exception
            }
           
catch (ThreadAbortException objException)
            {
               
// Log the exception

            }
           
catch (Exception objException)
            {

               
// Log the exception
                MessageBox.Show(objException.Message.ToString());
            }

        }

       
#endregion 

Here the main code is:

"wmic /namespace:" + "\"\\\\root/MicrosoftIISv2\"" + " /node:" + " \"%Your_ Server_Name%\" " + "path IISApplicationPool where (name like '%Your_IISAppool1%') call recycle";"

In "% Your_Server_Name%":- Give the name of the server whose AppPool you want to recycle.

In" %Your_IISAppool1%":- Give the name of IIS AppPool of the server you want to recycle.

Point to be noted

All the servers should be in the same network.

Interesting Feature

WMIC Code provides many features. Exploring this application was challenging; converting the command line WMIC code was great fun.

Application Front Snap

im1.gif

Login to add your contents and source code to this article
share this article :
post comment
 

Your wish My Command sir

Posted by Udit Dobhal Feb 24, 2012

Thanx .... Feeling great to be part of the community

Posted by Udit Dobhal Feb 21, 2012

u r welcome jessica.

Posted by Udit Dobhal Feb 21, 2012

Thanks a lot Amit.I will try my best to help out the community......

Posted by Udit Dobhal Feb 21, 2012

Good start, Welcome to the C# Corner.

Posted by Dinesh Beniwal Feb 21, 2012
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor