background preloader


Facebook Twitter


Multi-threading in .NET: Introduction and suggestions. One of the greatest understatements I've heard in a newsgroup was made by Patricia Shanahan, in a Java newsgroup in 2001: "Multi-threaded programming needs a little care.

Multi-threading in .NET: Introduction and suggestions

" Multi-threading is probably one of the worst understood aspects of programming, and these days almost all application programmers need to understand it to some extent. This article acts as an introduction to multi-threading and gives some hints and tips for how to do it safely. Warning: I'm not an expert on the subject, and when the real experts start discussing it in detail, my head starts to spin somewhat. However, I've tried to pay attention to those who know what they're doing, and hopefully the contents of this article form at least part of a multi-threading "best practice". Deadlock Detection in Existing Code. Free source code and progra. Introduction Deadlocks are common problems in multi-threaded programming.

Deadlock Detection in Existing Code. Free source code and progra

When it comes to multithreading development, the most common problem developers are facing is critical sections. It is not uncommon to use more than a single lock, but if one does not pay attention to the order of the locks, or to the context in which they are being called (e.g., from within a callback), deadlocks will form. (There are many reasons for deadlocks to occur other than the obvious critical section, e.g., two threads that are waiting for each other to signal an event, but we will not discuss them here).

As with anything that is related to threads, timing is everything. What if we could make the rare case the normal case? The attached ZIP file contains a DLL that does exactly that. Note that there is no need for the deadlock to really occur; rather, it is only important that suspected flows (or all flows) will be performed at least once. Using the code Analyzing the stacks (slockimp based) Thread synchronization: Wait and Pulse demystified. Free source. Table of Contents Introduction This short article is about the three less well understood methods of the Monitor class: Wait, Pulse, and PulseAll.

Thread synchronization: Wait and Pulse demystified. Free source

The MSDN documentation for these methods explains what they do, but not why or how to use them. Concurrent Affairs: More AsyncEnumerator Features. 5pm Posts: .Net Threads - 10 Best Practices. I have written earlier (here and here) about Threads.

5pm Posts: .Net Threads - 10 Best Practices

I thought it would be a good idea to list some of the 'best practices' that I have learnt to follow ... In general, one should use threads for long-running tasks. For example ... ThreadStart job = new ThreadStart(ThreadJob); Thread thread = new Thread(job); thread.Start(); static void ThreadJob() { // do something in here... } If using Monitor class to synchronize, ensure that Monitor.Exit is always called Monitor.Enter(this); try { y = this.y; } finally { Monitor.Exit(this); } Use Monitor.TryEnter to specify a timeout value. Bool lockAcquired = Monitor.TryEnter(this,2000); if (lockAcquired) { try { this.y = y; } finally { Monitor.Exit(this); } } else { // do something } Quantum Bit Designs » Blog Archive » Stop Polluting the UI Threa. Quantum Bit Designs Multithreading, WPF, .NET and Software Designs.

Quantum Bit Designs » Blog Archive » Stop Polluting the UI Threa

A basic NamedLock class. Free source code and programming help. Download source code - 1.08 KB Introduction There are a few problems I've come across where synchronizing a particular "name" might be useful.

A basic NamedLock class. Free source code and programming help

One of the apps I work on makes heavy use of Lucene.NET; each page shows the results of a couple of queries. It doesn't make a whole ton of sense to run multiple, identical queries against Lucene at the same time, so I generate a key for each query, lock against that key, and let the first thread do the actual work while the others sit around sipping coffee. Using the code. NParallel, A Small Parallel Execution Library - The Code Project. Important Updates NParallel0.2 is released with loop parallelism and multi-task support (For, ForEach, Do), together with a lot of other enhancements(parameterized async call for instance). The codes are almost rewriten and heavily commented for the intensional users.

VS2005 version will no longer be supported because later versions will rely highly on functional programming concept with C#3.0 lumbda. This article mainly remains to introduce the main construct of NParallel, for loop parallelism , I posted a new article discuss the design and usage of loop parallelism for NParallel, you could refer to the testcases attached. Introduction There are many ways to write multi-threading codes in .NET, like to use the asynchronous method invocation, create a thread etc. My previous project relies heavily on the Begin/EndInvoke model. Then I came up with NParallel, which I am going to introduce to you in this article. The Problem: Time Consuming Tasks The old ways, asynchronous method invocation. Bounded Blocking Queue (One Lock) - The Code Project - C# Progra. Threading in C# - Free E-book.

Threading in C# Joseph Albahari Last updated: 2011-4-27 Translations: Chinese | Czech | Persian | Russian | Japanese Download PDF Part 1: Getting Started C# supports parallel execution of code through multithreading.

Threading in C# - Free E-book

A C# client program (Console, WPF, or Windows Forms) starts in a single thread created automatically by the CLR and operating system (the “main” thread), and is made multithreaded by creating additional threads. All examples assume the following namespaces are imported: