Getting started with Model-View-ViewModel (MVVM) pattern using Windows Presentation Framework (WPF)

,
September 19, 2017 / No Comment

The Windows Presentation Framework (WPF) is built to take full advantage of the Model-View-ViewModel (MVVM) pattern. Though it is possible to create WPF applications without using the MVVM pattern, a little investment in learning can make building WPF applications much simpler.
If you are just getting started with WPF I would suggest taking a look at this getting started guide.
Read more

AUTHOR: CATEGORY: C#, WPF

C# 7.0: Tuples Explained

,
July 27, 2017 / No Comment

Back in November, in the Connect() special issue of MSDN Magazine, I provided an overview of C# 7.0 in which I introduced tuples. Click here for the overview. In this blog I delve into tuples again, covering the full breadth of the syntax options.
To begin, let’s consider the question:
Why tuples?
On occasion, you’ll likely find it useful to […]
Read more

AUTHOR: CATEGORY: Blog

Deterministic Finalization with IDisposable and the Using Statement

,
October 14, 2016 / No Comment

The problem with finalizers on their own is that they don’t support deterministic finalization (the ability to know when a finalizer will run). Rather, finalizers serve the important role of being a backup mechanism for cleaning up resources if a developer using a class neglects to call the requisite cleanup code explicitly.
For example, consider the TemporaryFileStream, which includes not […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#

Locking a Block of Code With an Integer

,
June 27, 2016 / No Comment

I was talking with a developer recently who was convinced that you could use a static integer variable to lock a block of code merely by casting it to an object, like this

First it must be noted that an integer cannot be used by itself in a lock statement because it is a value type. But when you […]
Read more

AUTHOR: CATEGORY: .Net, Blog, C#

Guidelines for Exception Handling in C#

,
September 14, 2015 / 1 Comment

The following is a list of C# Exceptions Handling Guidelines taken from Essential C# by Mark Michaelis.
Exception handling provides much-needed structure to the error-handling mechanisms that preceded it. However, it can still lead to some unwieldy results if used haphazardly. The following guidelines offer some best practices for exception handling.

Catch only the exceptions that you can handle.
Read more

AUTHOR: CATEGORY: .Net, C#

IntelliTect Presents at the Seattle Code Camp 2012

,
June 15, 2012 / No Comment

Asynchronous Programming with C# 5.0 – Mark Michaelis
In C# 5.0 there is really only one significant syntax addition – support for asynchronous programming that is embedded into the language. In this session we go over the is and is-nots of what C# 5.0 enables in the way of parallel processing – both for the UI and for the server […]
Read more

AUTHOR: CATEGORY: .Net, C#, Headlines, PowerShell

Parallel.For where i does not go to i++

,
April 25, 2010 / 1 Comment

A problem was recent posed that I hadn’t thought to do using Parallel.For in C#. How do you parallelize a for loop variable increased by something other than i++? Typically, I would simply iterate over a enumerable collection and run against the data in parallel using Parallel.For and Parallel.ForEach.

It turns out that there is no support for this in the PFX API. Parallel.For does not support incrementing other than one and it does not support reverse iteration. Also, Enumerable is a static class – which means we can’t do extension methods on Enumerable. However, we can use a custom iterator to generate the sequence for us. By using a Func<int, int> allows us to use our familiar i+= syntax for the increment function. We can quickly create a very simple iterator that will help us out.

AUTHOR: CATEGORY: .Net, Headlines, LINQ