This is part 4 in a series on using Task Parallel Library when writing server applications, especially ASP.NET MVC and ASP.NET Web API applications.
- Introduction
- SynchronizationContext
- ContinueWith
- TaskHelpers
Simple Task Helpers
I know we left off in part 3 with a problem, but we're not going to solve it yet, because we still need to build some foundation helper classes that will make it easier to do that. In particular, there are some good practices we can codify around the creation and conversion of tasks that led us to write the TaskHelpers class that we use today in ASP.NET Web Stack.
Continue reading "Task Parallel Library and Servers, Part 4: TaskHelpers" »
This is part 3 in a series on using Task Parallel Library when writing server applications, especially ASP.NET MVC and ASP.NET Web API applications.
- Introduction
- SynchronizationContext
- ContinueWith
- TaskHelpers
What ContinueWith Really Does
I promised that we had a bug in our previous code, and we did... sort of. Calling ContinueWith without any special flags will cause your continuation to always run, regardless of the final state of the task. We wrote our continuation under the assumption that the Task had completed successfully, which can lead to some very odd and hard to debug problems. Luckily, in our code, we ended up calling Result on the Task object, which turns around and throws an exception if the task had ended in a faulted or canceled state. But what if we'd had a Task rather than a Task<T>? Or what if we hadn't called Result? In .NET 4, this is considered a fatal error condition, and when the task object got garbage collected, its finalizer would've thrown an exception that takes down your AppDomain because you had an unobserved fault! Definitely not good.
Continue reading "Task Parallel Library and Servers, Part 3: ContinueWith" »
This is part 2 in a series on using Task Parallel Library when writing server applications, especially ASP.NET MVC and ASP.NET Web API applications.
- Introduction
- SynchronizationContext
- ContinueWith
- TaskHelpers
Introduction to SynchronizationContext
An important part of the work in properly handling tasks on the server is supporting the synchronization context. When you’re using .NET 4.5, then the await keyword automatically does this for you. When you’re consuming Task objects on .NET 4, though, getting yourself back onto the right synchronization context is critical; otherwise, you may cause errors in your application when trying to access things which touch the HttpContext in ASP.NET.
Continue reading "Task Parallel Library and Servers, Part 2: SynchronizationContext" »
This is part 1 in a series on using Task Parallel Library when writing server applications, especially ASP.NET MVC and ASP.NET Web API applications.
- Introduction
- SynchronizationContext
- ContinueWith
- TaskHelpers
Okay, let’s just get this out of the way:
Asynchronous (multi-threaded) programming is not easy.
This warning really has nothing to do with .NET in particular, because it can be quite challenging to do correctly on any framework, but here’s the good news:
Asynchronous programming with .NET 4 is a little easier.
Asynchronous programming with .NET 4.5 is a lot easier.
Continue reading "Task Parallel Library and Servers, Part 1: Introduction" »
Update: Visual Studio 11 Beta is now available to the public. We've released the runner for xUnit.net for VS11 Beta in the Extension Gallery.
Update: Visual Studio 11 Developer Preview is now available to the public.
Earlier this week at the //build/ windows conference, Jason Zander announced the availability of a new "developer-focused" unit test runner in Visual Studio 11. They shipped the first Developer Preview of Visual Studio 11, and it includes this new unit test runner. Peter Provost demonstrated the pluggability of this new unit test runner by showing (and writing) tests written in xUnit.net. We collaborated with Peter and wrote the prototype runner that he used on stage during his demos.
Continue reading "Prototype xUnit.net Visual Studio 11 Unit Testing Plugin" »
On the ASP.NET MVC team, we occasionally get questions about attributes and how they apply from interfaces to classes, like:
I have an interface IFoo defined like this:
public interface IFoo {
[Required]
string Name { get; set; }
}
And I have a model class defined like this:
public class ConcreteFoo : IFoo {
public string Name { get; set; }
}
Why doesn't the validation attribute from IFoo.Bar apply to ConcreteFoo.Bar?
The difference between base classes and interfaces in the CLR is responsible for this difference.
Continue reading "Interface Attributes != Class Attributes" »
A few months ago, I finished writing part of a book on ASP.NET MVC 3. I was honored to be asked to write the third edition of the book with fellow co-workers Phil Haack and Jon Galloway, and incredibly smart dude K. Scott Allen. This is very good company to be in for a first-time author. :)
The first edition of this book was written by some very impressive people, and it got terrific reviews. The second edition was mostly the same as the first. We took the feedback from the 2nd edition and decided that potential customers would appreciate it if we re-examined the structure of the book and provide as much new content as possible.
Continue reading "Professional ASP.NET MVC 3" »
Introduction
In ASP.NET MVC 2, we shipped both client- and server-side validation support. The client-side validation that we included in MVC 2 was a custom validation system written against ASP.NET Ajax. We also included an experimental version written against jQuery in the MVC Futures project.
In ASP.NET MVC 3 Beta, we’ve updated the runtime to enable a feature we’re calling “Unobtrusive Client Validation”. We have also created a consumer for these unobtrusive client validation attributes that uses jQuery and jQuery Validate to perform the validation on our behalf.
Continue reading "Unobtrusive Client Validation in ASP.NET MVC 3" »
Introduction
In ASP.NET MVC 1.0, we shipped Ajax helpers implemented as extension methods on the AjaxHelper class (and available via the Ajax property of your views). In the box, we shipped two category of Ajax helpers: Ajax links and Ajax forms. Both fundamentally did the same thing: make an asynchronous request, and do something with the result when you’re finished (including knowing whether you got back a success or failure response from the server).
In ASP.NET MVC 3 Beta, we've updated the runtime to enable a feature we're calling "Unobtrusive Ajax". We have also created a consumer for these unobtrusive Ajax attributes that uses jQuery to perform the Ajax requests on our behalf.
Continue reading "Unobtrusive Ajax in ASP.NET MVC 3" »