|
|
|
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
1242
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
Diagnostics
The System.Diagnostics namespace provides classes that enable you to debug and
trace code; start, stop, and kill processes; monitor system performance; and
read and write event logs. Table 21.1 describes some System.Diagnostics
namespace classes.
Table 21.1: System.Diagnostics Classes

The Process Class
The Process class retrieves various information pertaining to a process running
on the system and caches the information in memory. This means that if your
application requires up-to-date process information, you should frequently
refresh the process cache by calling the Process.Refresh() method. In addition
to simply retrieving the name of the current process, this class can provide
more information, such as the following:
-
Memory statistics
-
Process times
-
Thread statistics
-
Handle statistics
Table 21.2 describes the members of this class.
Table 21.2: Process Class Members

Listing 21.1 illustrates how to get the current process from the Process class.
In this case, the process would be the application name you gave to the
following code(Listing 21-1) after the code is compiled into an assembly.
Listing 21.1: Getting a Current Process
Imports System
Imports
System.Diagnostics
Namespace
DiagnosticsProcess
Class
Program
Shared
Sub Main(ByVal
args As String())
Dim
CurrentProcess As
Process = Process.GetCurrentProcess()
Console.WriteLine("ProcessName:
{0}", CurrentProcess.ProcessName)
End
Sub
End
Class
End
Namespace
Although you plan to enumerate processes currently running on the system, you
may not be authorized to access process-specific information. If any of the
Process class methods fail (usually with ACCESS_DENIED), that may throw an
exception corresponding to the failure. For example:
System.ComponentModel.Win32Exception: Access is denied
It has a method named GetProcesses() that returns all running processes on the
machine. The GetProcesses has two overloads: one for the local machine and
another for the remote machine. To see processes on the local machine, use
GetProcesses(); otherwise use GetProcesses(string machinename). Listing 21.2
shows how to list the first 20 running processes on your computer. You may opt
to loop or enumerate through all the processes from the returned array, but here
we just list 20.
Listing 21.2: Using GetProcess
Imports System
Imports
System.Diagnostics
Namespace
DiagnosticsProcess
Class
Program
Shared
Sub Main(ByVal
args As String())
Dim procList
As Process()
= Process.GetProcesses()
' or you can specify a
computer name
' Process[]
procList = Process.GetProcesses(@"MCBcomputer");
' output the
first 20 processes in the array
Dim i
As Integer = 0
While i <
20
Console.WriteLine("ProcessID:
{0}", procList(i).Id)
Console.WriteLine("ProcessName:
{0}", procList(i).ProcessName)
System.Math.Max(System.Threading.Interlocked.Increment(i),
i - 1)
End
While
End
Sub
End
Class
End
Namespace
Output

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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
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!
|
|
|
|
|
|
|
|
|
|
|
|
|