Do I need to dispose of a Task?

While the normal rule of thumb is to always call Dispose() on all IDisposable implementations, Task and Task<T> are often one case where it’s better to let the finalizer take care of this. The reason Task implements IDisposable is mainly due to an internal WaitHandle. This is required to allow task continuations to work properly, … Read more

How to pass a variable to the SelectCommand of a SqlDataSource?

Try this instead, remove the SelectCommand property and SelectParameters: <asp:SqlDataSource ID=”SqlDataSource1″ runat=”server” ConnectionString=”<%$ ConnectionStrings:itematConnectionString %>”> Then in the code behind do this: SqlDataSource1.SelectParameters.Add(“userId”, userId.ToString()); SqlDataSource1.SelectCommand = “SELECT items.name, items.id FROM items INNER JOIN users_items ON items.id = users_items.id WHERE (users_items.user_id = @userId) ORDER BY users_items.date DESC” While this worked for me, the following code also … Read more

Regex for all PRINTABLE characters

Very late to the party, but this regexp works: /[ -~]/. How? It matches all characters in the range from space (ASCII DEC 32) to tilde (ASCII DEC 126), which is the range of all printable characters. If you want to strip non-ASCII characters, you could use something like: $someString.replace(/[^ -~]/g, ”); NOTE: this is … Read more

Validate data using DataAnnotations with WPF & Entity Framework?

You can use the DataAnnotations.Validator class, as described here: http://johan.driessen.se/archive/2009/11/18/testing-dataannotation-based-validation-in-asp.net-mvc.aspx But if you’re using a “buddy” class for the metadata, you need to register that fact before you validate, as described here: http://forums.silverlight.net/forums/p/149264/377212.aspx TypeDescriptor.AddProviderTransparent( new AssociatedMetadataTypeTypeDescriptionProvider(typeof(myEntity), typeof(myEntityMetadataClass)), typeof(myEntity)); List<ValidationResult> results = new List<ValidationResult>(); ValidationContext context = new ValidationContext(myEntity, null, null) bool valid = Validator.TryValidateObject(myEntity, context, … Read more