Browse by Tags

Tagged Content List
  • Blog Post: Using Async for File Access

    by Alan Berman The new Async feature in Visual Studio makes it easy to code asynchronous method calls. To make synchronous code asynchronous, you can simply call an asynchronous method instead of a synchronous method and add a few keywords to the code, as shown in the examples below. You no longer...
  • Blog Post: Blocking Collection and the Producer-Consumer Problem

    This time I want to discuss features that belong to the new System.Collections.Concurrent namespace in the.NET Framework 4. When you design parallel applications, you often need thread-safe data storage as well as some mechanism of sending messages between tasks. Once again, this post will touch on just...
  • Blog Post: Parallel Programming: Task Cancellation

    In this post, which is the third one in my parallel programming introduction series, I want to show how you can cancel parallel operations when working with the Task Parallel Library (TPL) . I’m going to modify the program that I started in the previous posts. By the way, here’s the full list of posts...
  • Blog Post: Parallel Programming: Task Schedulers and Synchronization Context

    Thanks to everyone who provided feedback on my previous post Parallel Programming in .NET Framework 4: Getting Started . As promised, I am continuing the series. This time, let’s go a little bit deeper and talk about task schedulers , synchronization context , tasks that return values , and some other...
  • Blog Post: Parallel Programming in .NET Framework 4: Getting Started

    With this post I want to start a series devoted to the new parallel programming features in .NET Framework 4 and introduce you the Task Parallel Library (TPL) . Update. The list of posts in this series: Getting Started (this post) Task Schedulers and Synchronization Context Task Cancellation Blocking...
  • Blog Post: How can I get objects and property values from expression trees?

    This is a follow-up to the Getting Information About Objects, Types, and Members with Expression Trees post, so I would recommend that you read that one first. Among other code examples in that blog post, I demonstrated how you can get a property name as a string by using expression trees. Here is the...
  • Blog Post: Covariance and Contravariance FAQ

    In this post I’ll try to answer the most common questions I find on forums and in documentation feedback about C# covariance and contravariance. It’s a big topic for a single blog post, so expect to see a lot of “more information” links. Special thanks to Eric Lippert and Chris Burrows for reviewing...
  • Blog Post: Getting Information About Objects, Types, and Members with Expression Trees

    Starting with C# 3.0 and Visual Studio 2008, you can use expression trees to get information about objects, types, and members. In this post I’m going to show some examples and explain what benefits you can get by using this technique. If you are not familiar with expression trees, I would recommend...
  • Blog Post: Debugging Expression Trees in Visual Studio 2010

    First of all, let’s take a look at the example from one of my previous posts . It creates an expression tree for calculating the factorial of a number. ParameterExpression value = Expression .Parameter( typeof ( int ), "value" ); ParameterExpression result = Expression .Parameter( typeof ( int...
  • Blog Post: Dynamic in C# 4.0: Creating Wrappers with DynamicObject

    In the previous post I showed how you can use the new dynamic feature and the ExpandoObject class to add and remove properties at run time, and how this can make your code more readable and flexible than code written with LINQ to XML syntax. But there were some obvious flaws in that example: While...
  • Blog Post: Dynamic in C# 4.0: Introducing the ExpandoObject

    You have probably already heard about the new dynamic feature in C# 4.0 and how it is used to support COM interop. If you haven't, I strongly recommend reading the following MSDN articles: Using Type dynamic and How to: Access Office Interop Objects by Using Visual C# 2010 Features . Well, where else...
  • Blog Post: Generating Dynamic Methods with Expression Trees in Visual Studio 2010

    Expression trees first appeared in Visual Studio 2008, where they were mainly used by LINQ providers. You can use expression trees to represent code in a tree-like format, where each node is an expression. You can also convert expression trees into compiled code and run it. This transformation enables...
  • Blog Post: How to use LINQ methods to compare objects of custom types

    LINQ provides a convenient syntax and many useful methods for operating with collections of objects. However, to be correctly processed by LINQ comparison methods such as Distinct or Intersect , a type must satisfy certain requirements. Let’s take a look at the Distinct method, which returns all distinct...
  • Blog Post: How do I calculate a MD5 hash from a string?

    It is a common practice to store passwords in databases using a hash. MD5 (defined in RFC 1321 ) is a common hash algorithm, and using it from C# is easy. Here’s an implementation of a method that converts a string to an MD5 hash, which is a 32-character string of hexadecimal numbers. public string...
  • Blog Post: How do I play default Windows sounds?

    Sometimes, you might want to make your application a bit more audible. If you are using .NET 2.0, you can utilize the new System.Media namespace and its SystemSound and SystemSounds classes. The SystemSounds class contains five static properties that you can use to retrieve instances of the SystemSound...
  • Blog Post: Where can I find design and coding guidelines for .NET?

    tipu_77 asked "What are microsoft suggested naming conventions in C#?" The .NET Framework Team collects their recommendations at their GotDotNet community site . which points to a fairly comprehensive MSDN page Design Guidelines for Class Library Developers . which includes the section Naming Guidelines...
  • Blog Post: How do I get and set Environment variables?

    Use the System.Environment class. Specifically the GetEnvironmentVariable and SetEnvironmentVariable methods. Admitedly, this is not a question specific to C#, but it is one I have seen enough C# programmers ask, and the ability to set environment variables is new to the Whidbey release, as is the EnvironmentVariableTarget...
  • Blog Post: What is the equivalent to regsvr32 in .NET?

    Where you once used Regsvr32 on unmanaged COM libraries, you will now use Regasm on managed .NET libraries. “ Regsvr32 is the command-line tool that registers .dll files as command components in the registry“ “Regasm.exe, the Assembly Registration tool that comes with the ...
  • Blog Post: How can I run another application or batch file from my Visual C# .NET code?

    Posted by: Duncan Mackenzie , MSDN This post applies to Visual C# .NET 2002/2003 Suppose you want to run a command line application, open up another Windows program, or even bring up the default web browser or email program... how can you do this from your C# code? The answer for all of these examples...
Page 1 of 1 (19 items)