Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to count number of processors on current machine, and getting command line of your program process using “Environment Class” in C# (.net 2.0).

Author: Zunnair
Download Source Code : 860_source.zip

In this article you will learn that how we can count the number of processors on current machine and how you can get your program process command line in C# and VB.

 

Count of Processors:
As we know that now a day a machine can have number of processors in it. Dot net provides us a class named “Environment”. This class provides us many facilities to getting our system information. It provides us a property to count the number of processors in the machine.
For this purpose you can use Processor Count Property. It returns an integer which tells you the number of processors.
To demonstrate make a window application. Drag one text box and one button on the form. Press button. You will get count in text box.
Now write the following code on button click event
C#
private void btn_count_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = Convert.ToString(System.Environment.ProcessorCount);
            txt_processors.Text = str;
        }
VB
Private Sub btn_count_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = Convert.ToString(System.Environment.ProcessorCount)
        txt_processors.Text = str
    End Sub
This simple code gets the number of processors in current machines.
Get Command Line:
Environment class also provides us a facility to get a facility to get command line of our process. For this you can use Property Command Line. It returns string.
To demonstrate make a window application. Drag one text box and one button on the form. Press you will get command line in text box.
Now write the following code on button click event:
 
C#
private void btn_command_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = System.Environment.CommandLine;
            txt_command.Text = str;
        }
VB
Private Sub btn_command_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = System.Environment.CommandLine
        txt_command.Text = str
    End Sub
This is simple code to get command line of your process.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
 
            this.Text = "Devasp.net Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
 
        Me.Text = "Devasp.net Application"
 End Sub
 
This simple article tells how we can count the number of processors on current machine and how you can get your program process command line in VB and C #.net 2.0.

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to do Sorting using Merge Sort algorithm in C# (.net 2.0)

Disclaimer - Privacy
© 2002-2017 DevASP.net