.NET news » C# C# Rss Feed

download
Deadlock monitor
Q: I'm using locks in my application to synchronize work on a bunch of threads. Unfortunately, I'm doing something incorrectly and my threads seem to just stop sometimes. I think I'm running into deadlocks, but I'm not sure how to find them. Is there any way I can do so programmatically? I'd like an exception to be thrown when a deadlock is encountered.
A: First, it's important to understand what a deadlock among threads is and the conditions that lead to one. Threads deadlock when waiting on each other to release some resources, but by performing that blocking wait, they're not releasing the resources the other threads need in order to unblock. The threads can't make any progress until the resources are released, but because they're not making progress, the resources will never be released, the threads are locked up, and thus "deadlock"...
21 Aug 2007, 19:00:00   Source: Deadlock monitor   Tags: C#
Simple Threading

This is a simple example taken from MSDN about multi-threading or, the way I like to say it, "Doing two things at once." I've modified the original example to make it easier to see how everything interacts. Easier for me anyway, since we are all different. One explanation may be adequate for some and not for others. I hope this can shine some light for some, as it did for me.

Far from being any type of Guru on the subject, I'll try and explain it the best I can from my point of view. I honestly don't understand everything about threads, delegates and so on. The important thing in my mind is that I understood enough to have it do what I wanted in the end. The next step is understanding the rest.

7 Aug 2007, 14:24:00   Source: Simple Threading   Tags: C#
Collections Best Practices
In the .NET Framework, a lot of effort went into creating collection classes that are powerful and that address a variety of needs and styles. These collections are simple to use, intuitive, and have adequate performance—all very important characteristics. In this month’s installment, I’ll look at collections in .NET, how they work, when to use them, and some best practices.
18 Jun 2007, 19:00:00   Source: Collections Best Practices   Tags: C#
IEnumerable and Yield in .NET 2.0
IEnumerable is an interface that has allowed for the creation of collections which can be iterated with a foreach loop since .NET 1.0. Well, with the introduction of generics and the yield keyword in .NET 2.0 things have gotten a whole lot simpler. This article will demonstrate how to use the generic IEnumerable<> interface along with the new yield keyword to create collections on the fly, without the need to implement all of the boiler plate code that was previously required.
8 Jun 2007, 14:01:00   Source: IEnumerable and Yield in .NET 2.0   Tags: C#
Digging into IDisposable

One of the major productivity benefits that the common language runtime (CLR) offers developers of managed code is that the garbage collector (GC) makes sure any memory allocated on the managed heap is cleaned up after it is no longer needed. Developers are thus saved countless hours of debugging difficult problems arising from memory leaks, from trying to use released memory, and from double-freeing memory. However, while the garbage collector is great at making sure that memory does not leak, it doesn’t have any knowledge about other resources that need to be freed. For instance, the garbage collector doesn’t know how to close a file handle or how to release memory allocated outside of the managed heap with an API such as CoAllocTaskMem.

One problem with this system is that the garbage collector does not run deterministically and, as a result, your object may not be finalized for a long time after the last reference to it has gone away.

To avoid having to wait an indeterminate amount of time for the garbage collector to act, types that own resources should implement the IDisposable interface; then consumers of that type can release those resources in a timely manner.

21 May 2007, 19:00:00   Source: Digging into IDisposable   Tags: C#
Multi Index Container for C# 2.0
Some of us have had a need for associative containers having more than one index, sometimes we also need associative containers with non-unique keys. Boost.MultiIndex provides a sophisticated library of container having more than one indexing mechanism. Need for similar data structure in C# (.Net) and introduction of generics in .Net pushed me to design multi-index container similar concept.
20 May 2007, 23:21:00   Source: Multi Index Container for C# 2.0   Tags: C#
Interfaces in C# for beginners
Interfaces in C # provide a way to achieve runtime polymorphism. Using interfaces we can invoke functions from different classes through the same Interface reference, whereas using virtual functions we can invoke functions from different classes in the same inheritance hierarchy through the same reference. Before things start getting difficult let me start using simple and short examples to explain the concept of interfaces..
10 May 2007, 14:24:00   Source: Interfaces in C# for beginners   Tags: C#
Comparing Values for Equality in .NET: Identity and Equivalence
An article clarifying the various ways of comparing two values for equality in .NET
8 May 2007, 17:31:00   Source: Comparing Values for Equality in .NET: Identity and...   Tags: C#
C# Language Infrequent Methods,Operators and Techniques
Here I am providing a basic overview of some things which are included in .NET 2.0 but only few developers are using them. I am not saying that nobody knows about these functions, operators or facilities but only few developers are using these based on their requirements.
4 May 2007, 09:28:00   Source: C# Language Infrequent Methods,Operators and Techniques   Tags: C#
Asynchronous design patterns.
This article describes the asynchronous design pattern, it's implementation, it's limitations and ways to improve the situation in certain circumstances.
24 Apr 2007, 18:55:00   Source: Asynchronous design patterns.   Tags: C#