Visual Basic .NET MyServices Namespace

Posted Thursday, December 9, 2004 4:44 PM by C-Dog's .NET Tip of the Day
While the C# team was working on thing of <del>no-importance</del> great importance like generics, the VB.NET team has worked diligently on creating a new series of classes called the My Classes.  These classes provide a series of basic functionality that provide features for everything from logging, getting computer information, playing sounds, and opening serial ports.
 
All the methods are considered static when used through Visual Basic.  Here is an example of how to play a WAV file using Visual Basic .NET.
 
My.Computer.Audio.Play("c:\Windows\Media\chimes.wav")
 
Some of the other classes available are: MyClock, MyComputer, MyComputerInfo, MyLog (huh huh), MyNetwork, and MyPrinters.  The MyComputer class hosts properties including FileSystem, Keyboard, Moouse, Registry, and Screen.  The MyComputerInfo class provides properties to get information such as the MachineName, OSVersion, Physical Memory, etc.
 
Now don't run out and switch to VB just yet (sorry, Marcus).  These classes are available in the Microsoft.VisualBasic.MyServices namespace.  To get access to that namespace, just add a reference to Microsoft.VisualBasic.dll.
 
Here is the above example in C#.
 
// instantiate myAudio object
MyAudio myAudio = new MyAudio();
 
// play a wav file
myAudio.Play("C:\\WINDOWS\\Media\\Chimes.wav");
 
In C#, the only extra step you have to take is to instantiate the object first.  The MyServices namespace is worth exploring because they make a lot of taks that sometimes took a bit of code really simple.
 

Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=218