Inside and Out...

An attempt to understand technology better...

  Home  |   Contact  |   Syndication    |   Login
  160 Posts | 0 Stories | 12 Comments | 181 Trackbacks

News


WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Twitter





Tag Cloud


Archives

Post Categories

Image Galleries

Links

VB 2005 is introducing the concept of My that allows the developer to write code which can get details pertaining to currently logged in user - for instance, the MyComputerInfo class allows you to get details like your machine's name, total physical and virtual memory, available memory, etc. Likewise, MyAudio is another class that provides you functionality to play audio on your system.

My does not give you any new functionality - it simply saves the developer from delving deep inside the FCL to get the same information which My will give you in a single namespace. However, this functionality is available to VB 2005. What about other managed languages? Can't they use it?

And the answer is yes! They can. All you have to do is set a reference to Microsoft.VisualBasic.dll assembly and use the Microsoft.VisualBasic.MyServices namespace. Below is sample C# source code that illustrates the use of My in C#:

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic.MyServices; // this contains the "My" classes

#endregion

namespace MyCSDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            MyComputerInfo refMCInfo = new MyComputerInfo();
            ulong ulMB = 1024*1024;

            Console.WriteLine("Machine Name: {0}", refMCInfo.MachineName);
            Console.WriteLine("Physical Memory: {0} MB", refMCInfo.TotalPhysicalMemory / ulMB);
            Console.WriteLine("OS: {0} Version: {1}", refMCInfo.OSFullName, refMCInfo.OSVersion);
        }
    }
}
posted on Monday, November 01, 2004 8:00 PM

Feedback

# re: Using "My" in C# (and other managed languages) 11/1/2004 9:05 PM Daniel Moth
But what about the new VB startup model and application events?

I have detailed coverage of this here: http://www.danielmoth.com/Blog/2004/09/c-with-myevents-functionality.html

# C# でも My 11/2/2004 8:43 AM 米田 Blog ( SQL Server MEMO )
C# ?? My

# re: Using "My" in C# (and other managed languages) 2/26/2007 2:40 PM Ofer
Thanks man, you saved me !! :-)

But your code didn't work -
"undefined type MyComputerInfo".

But it helped me find this, I hope you enjoy it.


Thanks again!


string strHostName = Dns.GetHostName();
string hostIPs = string.Empty;
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);
// Enumerate IP addresses
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
hostIPs += (ipaddress.ToString() + " ");
}


ComputerInfo hostInfo = new ComputerInfo();
ulong ulMB = 1024 * 1024;
Clock hostClock = new Clock();
Network hostNetwork = new Network();
ServerComputer hostServer = new ServerComputer();


string result = string.Format("Host <{0}>, IPs <{1}>, OS ver <{2}>, Free Physical Memory <{3} MB>" +
", Free Virtual Memory <{4} MB>, GMTTime <{5}>",
strHostName, hostIPs, Environment.OSVersion.ToString(), hostInfo.AvailablePhysicalMemory / ulMB,
hostInfo.AvailableVirtualMemory / ulMB, hostClock.GmtTime());

# re: Using "My" in C# (and other managed languages) 6/1/2007 12:58 PM Ira
Where can I download or find the .dll you reference to use "My" ? (doesn't automatically install w/ VS 2005 Professional Edition)

Comments have been closed on this topic.