Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Visual Basic Language » Diagnostics and Process in VB.NET: Part 2

Diagnostics and Process in VB.NET: Part 2

In this article I will explain you about the Diagnostics and Process in VB.NET.

Author Rank :
Page Views : 1204
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


As you read Process in previous article now this is reaming part. The Process class offers properties from which you can learn things about a process. You can also start a process, close it, and kill it if you have the right authorization. Listing 21.3 depicts some of the important process methods with inline comments.

Listing 21.3: Various Process Methods

    ' you can start process with Start method
    process.Start()
        ' wait until the application is in an idle message loop state indefinitely
    process.WaitForInputIdle()
        ' wait until the application is in an idle message loop state 500miliseconds
   
    ' process.WaitForInputIdle(500);
        ' try to close the application main window GUI.
        ' you cannot close processes on remote computers!
        ' use Close() for console and GUI-based applications!
       
' but always prefer using CloseMainWindow() for GUI apps!
    If Not process.CloseMainWindow() Then
        ' you can Kill process with Kill method if you cannot close it
           process.Kill()
    End If

The EnterDebugMode method of the Process class puts the process in the debug state, and the LeaveDebugMode method forces the process to exit the debug state and return to the normal state.

Process Threads

A process consists of at least one thread, the primary execution thread, which can spawn more needed threads. You should limit the total number of threads because synchronization and contextswitching operations can drain the performance of the thread actions. The number of threads you allow depends on your resources and code. Thus, at the outset, we recommend you limit the maximum concurrent threads to a modest number, but do leave the maximum number of threads option of your process as configurable via the registry or other means such as the application *.ini file. The application consumer can monitor the default application performance and then reduce or augment the maximum number of threads if fine-tuning is necessary.

All process threads share the address space of the primary execution thread. A thread is made up of code, data, and other resources such as open files, semaphores, and dynamically allocated memory. Process threads share process resources. Each thread has a private thread local storage (TLS) area for its memory operations. Threads run in various intervals inside a process according to priorities assigned by the code and operating system. An atomic system scheduler gives execution control to threads in a round-robin fashion. The threads are run in clockwise order, each thread running in a time slice inside a virtual ring. The system scheduler determines which threads should run and when, so you do not need to worry about this aspect of thread execution. However, threads with lower priority use less CPU cycles to execute their code than higher-priority threads. To balance the CPU load on systems with multiple CPUs, the system scheduler may opt to move some threads to other CPUs. Listing 21.4 shows how you can list the running processes and their spawned threads on your system.

Listing 21.4: Listing Threads

    Imports System
    Imports System.Diagnostics
    Imports System.Timers
    Namespace DiagnosticsProcess
        Class Program
            Shared Sub Main(ByVal args As String())
                Dim CurrentProcess As Process = Process.GetCurrentProcess()
                Dim threadList As ProcessThreadCollection = CurrentProcess.Threads
                Console.WriteLine("ProcessName: {0}", CurrentProcess.ProcessName)
                For Each thr As ProcessThread In threadList
                    Console.WriteLine("Thread ID: {0}", thr.Id)
                    Console.WriteLine("Thread Priority Level: {0}", thr.PriorityLevel)
                    Console.WriteLine("Thread Total Processor Time: {0}", thr.TotalProcessorTime)
                Next
            End Sub
        End
Class
    End Namespace

Output

process2.gif

Conclusion

Hope this article would have helped you in understanding the Diagnostics and Process in VB.NET.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Dinesh Beniwal
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
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.
Dynamic PDF
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.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.