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 Check that “”CLR has started shutting down our process and how to get current stack trace information using “Environment Class” in C# (.net 2.0).

Author: Zunnair
Download Source Code : 869_source.zip

In this article you will learn that how we can Check that “”CLR has started shutting down our process and how to get current stack trace information using “Environment Class” in C# (.net 2.0).

 

Has Shutting Down?
Environment class provides us a facility to check that common language runtime is shutting down our program process or unloading current application domain.
For this purpose you can use Property Has Shutting Down provided by environment class. This property returns Boolean value.
To demonstrate make a window application. Drag one text boxes and one button on the form. Press button.
Now write the following code on button click event
C#
private void btn_ShuttingDown_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            bool b;
            b = Environment.HasShutdownStarted;
            str = b.ToString();
            txt_value.Text=str;
        }
VB
Private Sub btn_ShuttingDown_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        Dim b As Boolean
        b = Environment.HasShutdownStarted
        str = b.ToString()
        txt_value.Text = str
    End Sub
This simple code tells that CLR is shutting down current process or not.
Stack Trace:
Environment class provides us a facility to get the current stack trace information. For this purpose you can use property stack trace. It returns string.
To demonstrate make a window application. Drag one text boxes and one button on the form. Press button.
Now write the following code on button click event:
 
C#
private void btn_StackTrace_Click(object sender, EventArgs e)
        {
            string str;
            str = Environment.StackTrace;
            txt_Value2.Text = str;
        }
VB
Private Sub btn_StackTrace_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String
        str = Environment.StackTrace
        txt_Value2.Text = str
    End Sub
This is simple code to get current stack trace information.
After invoking the property the Stack Trace information will look like:
   At System.Environment.GetStackTrace (Exception e, Boolean needFileInfo)
   At System.Environment.get_StackTrace ()
   At source.Form1.btn_StackTrace_Click (Object sender, EventArgs e) in C:\Documents and Settings\name\My Documents\Visual Studio 2005\Projects\source\source\Form1.cs:line 36
   At System.Windows.Forms.Control.OnClick (EventArgs e)
   At System.Windows.Forms.Button.OnClick (EventArgs e)
   At System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent)
   At System.Windows.Forms.Control.WmMouseUp (Message& m, Mouse Buttons button, Int32 clicks)
   At System.Windows.Forms.Control.WndProc (Message& m)
   At System.Windows.Forms.ButtonBase.WndProc (Message& m)
   At System.Windows.Forms.Button.WndProc (Message& m)
   At System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message& m)
   At System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message& m)
   At System.Windows.Forms.NativeWindow.DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   At System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   At System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context)
   At System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context)
   At System.Windows.Forms.Application.Run (Form mainForm)
   At source.Program.Main () in C:\Documents and Settings\name\My Documents\Visual Studio 2005\Projects\source\source\Program.cs:line 17
   At System.AppDomain.nExecuteAssembly (Assembly assembly, String [] args)
   At System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args)
   At Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly ()
   At System.Threading.ThreadHelper.ThreadStart_Context (Object state)
   At System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state)
   At System.Threading.ThreadHelper.ThreadStart ()
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 Check that “”CLR has started shutting down our process and how to get current stack trace information using “Environment Class” in C# (.net 2.0).

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Char operations (To Lower, To Upper, To String, Try Parse) using “Char Class” in C# (.net 2.0) PART5.

Disclaimer - Privacy
© 2002-2017 DevASP.net