Send mail to the author(s)

    July 23, 2008

    Lambda expressions in .NET Compact Framework 2.0

    There's been a lot of internal discussion today on how to leverage C# 3.0 features without requiring .NET Compact Framework 3.5. Mark has the low down on using extension methods with a little compiler misdirection hack.

    The discussions kicked off because I discovered that you can use lambda expressions with .NET Compact Framework 2.0 projects in Visual Studio 2008. I even twittered about it yesterday. (Note: it didn't take me too long to realize it's not a bug, but due to Visual Studio 2008 using the C# 3.0 compiler.) Code like the following just works -- no hacks required:

    delegate double PowerOf(double x, double y);
    
    static void Main() 
    {
        PowerOf pwr = (x, y) => Math.Pow(x, y);
        double result = pwr(2, 3);
    }

    If you are using Visual Studio 2008 and still need to target .NET Compact Framework 2.0, the little things like this go a long way to creating and maintaining reusable code.

    July 16, 2008

    OpenNETCF is now a Microsoft Gold Partner

    Over the last few months we've been working hard to attain the Gold Level partner status in the Microsoft Partner Program and I'm extremely pleased to say that we've done it! For our customers, this is an assurance that by choosing to work with OpenNETCF products and our consultants, you really are choosing a high calibre company.

    Massive amounts of credit for Mark for driving this internally. Good job!

    July 11, 2008

    Mark your calendars - Smart Device Development Chat, July 16.

    The next Smart Device Development Chat will take place on MSDN at 10am PST on Wednesday, July 16.

    Please join experts from the Windows Mobile, Windows CE, SQL Server CE and .NET Compact Framework communities in a chat around application development for smart devices. These chats are a great opportunity to have your questions answered by experts from around the world.

    Add to Calendar

    If you cannot attend the MSDN Chat, there is a permanent chat room available on the web and via IRC (irc://irc.freenode.net/mobiledev). Engage with your peers online today!

    June 24, 2008

    HOW-TO: Disable/Enable Network Connections Programmatically under Vista

    I got an email last week asking about how to disable a particular network connection under Vista. The specific scenario, how to disable an active 3G connection, is not something I'm going to cover, but what I present below could be used as basis for that scenario.

    With Vista, Microsoft introduced two new methods to the Win32_NetworkAdapter class under WMI: Enable and Disable. Before can call either of those methods, we need to know how to enumerate the network connections.

    The .NET Framework SDK provides a helpful utility called mgmtclassgen.exe, which can be used to create .NET-friendly wrappers of the WMI classes. Open up a Visual Studio command prompt and enter the following:

    mgmtclassgen Win32_NetworkAdapter -p NetworkAdapter.cs

    This will generate a file called NetworkAdapter.cs which will contain a C# representation of the WMI Win32_NetworkAdapter class. You can add this source code file to your C# project and then access all the properties without too much extra effort.

    To filter and disable the specific adapters, you do something like this:

    SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "NetConnectionStatus=2");
    ManagementObjectSearcher search = new ManagementObjectSearcher(query);
    foreach(ManagementObject result in search.Get())
    {
        NetworkAdapter adapter = new NetworkAdapter(result);
    
        // Identify the adapter you wish to disable here. 
        // In particular, check the AdapterType and 
        // Description properties.
    
        // Here, we're selecting the LAN adapters.
        if (adapter.AdapterType.Equals("Ethernet 802.3")) 
        {
            adapter.Disable();
        }
    }

    Don't forget to add a reference to System.Management.dll!

    June 16, 2008

    Chat Transcript: May 13, 2008 - Smart Device Development Chat

    A little later than I intended, but here is the transcript to Smart Device Development chat from May 13, 2008: Read it here