Visual Studio Tip: Show Threads in Source

Tuesday, May 29, 2012

Debugging multithreaded applications is always hard, so any help we can get from the debugger is appreciated. Here’s one tip that can help using Visual Studio 2010 when many threads are running at the same time, some of which run similar code.It’s tedious to lookup each thread’s call stack to see where its next instruction pointer is located. Here’s the Threads window in action: To find the actual source line each thread is at the breakpoint moment, we’ll need to switch to that thread by double clicking it in the Threads window and then we’ll see something like...

Asynchronous Programming with C# 5.0 & .NET 4.5 Session

Monday, March 26, 2012

This morning I gave a session on asynchronous programming with C# 5.0 at Microsoft offices in Ra’anana. Thank you all for attending, it was great fun! As promised, the presentation slides and demos are attached below (the Windows 8 demos can naturally be run on Windows 8 only). The session was recorded, so if you missed it, or just want to hear the same jokes again, the recording will be available in a few days – check out the MSDN blog for details of availability. Async Demos Async Metro Demo Presentation Slides

What happened to asynchrony with WebClient in .NET 4.5?

Saturday, March 17, 2012

In the Visual Studio 2010 Async CTP, a bunch of extension methods have been added to the WebClient class, to facilitate the “awaiting” of C# 5.0, such as DownloadStringTaskAsync, which can be simply used like so: var wc = new WebClient(); string result = await wc.DownloadStringTaskAsync(""); One of the overloads present in the CTP accepts a CancellationToken, so that the operation could be cancelled by an external CancellationTokenSource. For example: async Task<string> GetData(string uri, CancellationToken token) {     var wc = new WebClient();     string result = await wc.DownloadStringTaskAsync(new...
no comments

From Enumerable to Observable

Wednesday, January 18, 2012

The IEnumerable<T> interface represents a collection of objects of type T, and is used heavily thanks to the C# foreach construct. Better yet, in the LINQ world, this is the interface that is “extended” via extension methods by the System.Linq.Enumerable class. This makes IEnumerable<T> both easy to use as well as powerful. But is it the best interface for getting data out of a possible collection? Recap: what is IEnumerable<T>? IEnumerable<T> has only one method: GetEnumerator(), that returns an enumerator (what else?), sometimes called an iterator. IEnumerable<T> public interface IEnumerable<out T> : IEnumerable {     new...

Calculating PI in .NET

Friday, December 30, 2011

I always loved mathematics. Although I’m certainly not a mathematician by profession, I’m always intrigued and inspired by math’s pureness and cleverness. One of the simplest and fascinating aspects of math is the number PI. Described simply as the ratio of a circle’s circumference to its diameter, it’s a constant with infinite digits after the decimal point and most importantly, non repeating (at least as far as I know). There are many ways to calculate PI, as evident within the PI Wikipedia link. I wanted to see how I can get a large number of digits of...

Parallel Programming Open House Session

Thursday, December 1, 2011

Today I presented a half-day session on Multithreading & Parallel Programming at John Bryce center in Tel Aviv. Thank you all for attending! I certainly enjoyed presenting these fascinating topics. I’ve attached the demos I showed. The presentation will be sent to those who attended by email. Thank you! ParallelDemos

Some Short Videos I Made

Thursday, May 26, 2011

I’ve created a few short videos, covering some introductory material – still may be useful for some… The audio quality is not the best possible, but should be fairly understandable. All the videos are in Hebrew (sorry, non-Hebrew speakers! You can still watch me type code samples, it may have some value) The videos are: Introduction to C# 5.0 asynchronous programming Introduction to the Managed Extensibility Framework (MEF) Understanding XAML (Part 1) Understanding XAML (Part 2)   They are also available (or will be shortly) on the Hi-Tech TV web site....

PSSCOR4 Debugger Extension Released

Friday, April 29, 2011

A while back, Microsoft released the PSSCOR2 debugger extension for WinDbg, supporting more command than the classic SOS.DLL. This was for CLR v2 (.NET 2-3.5). Now a similar extension has been released for CLR 4 (.NET 4). You can download it here. There are versions for x86 and x64. The easiest way to use them is copy the relevant DLL to the .NET framework directory for the corresponding “bitness” (where SOS lives, something like C:\Windows\Microsoft.NET\Framework\v4.0.30319 (32bit) or C:\Windows\Microsoft.NET\Framework64\v4.0.30319 (64bit)) and then use .loadby psscor4 clr to load the extension. Then type !help to look at all the...

Dealing With Native DLLs in .NET “AnyCPU” Builds

Sunday, February 13, 2011

A .NET application can be compiled using the “AnyCPU” configuration, meaning the application runs as 32 bit on a 32 bit OS, and 64 on a 64 bit OS. As long as the application is purely managed, everything should be just fine. However, if the application must use some native DLL through interop (e.g. P/Invoke), then “AnyCPU” may be an issue. A native DLL cannot be both 32 and 64 bit – it’s one or the other. The traditional solution to the problem is to switch the .NET build to a “Win32” or “x64” configuration, thus aligning...