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 Terminate process using exit code and getting new line string define for you environment using “Environment Class” in C# (.net 2.0).

Author: Zunnair
Download Source Code : 866_source.zip

In this article you will learn that how we can terminate our process using exit code and getting new line string define for your environment in C# and VB.

 

Terminate processes by exit code:
In one of my previous articles I told that how we can get and set exit code for our process. Environment class provides us facility to terminate our process by using exit code.
For this purpose you can use a function Exit ().This function is provided by Environment Class. It takes an integer which is exit code of process and terminates the process. It returns nothing.
To demonstrate make a window application. Drag one text box and one button on the form. Write code in text box and press button, your process will terminate.
Now write the following code on button click event
C#
private void btn_terminate_Click(object sender, EventArgs e)
        {
            string str;
            str = txt_Code.Text;
            int code = Convert.ToInt16(str);
            System.Environment.Exit(code);
        }
VB
Private Sub btn_terminate_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String
        str = txt_Code.Text
        Dim code As Integer = Convert.ToInt16(str)
        System.Environment.[Exit](code)
    End Sub
This simple code terminates your program using exit code.
Get New Line String:
Environment class also provides us a facility to get a new line string define for our environment. For this you can use Property New Line. It returns string.
To demonstrate make a window application. Drag one text box and one button on the form. Press button you will get new line string in text box.
Now write the following code on button click event:
 
C#
private void btn_line_Click(object sender, EventArgs e)
        {
            string str;
            str = System.Environment.NewLine;
            txt_string.Text = str;
        }
VB
Private Sub btn_line_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String
        str = System.Environment.NewLine
        txt_string.Text = str
    End Sub
This is simple code to get new line string define for your environment.
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 terminate our process using exit code and getting new line string define for your environment in C# and VB.
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Char operations (Is surrogate, is number, and is punctuation) using “Char Class” in C# (.net 2.0) PART3.

Disclaimer - Privacy
© 2002-2017 DevASP.net