background preloader

Threading in C# - Free E-book

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. 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: using System; using System.Threading; class ThreadTest{ static void Main() { Thread t = new Thread (WriteY); t.Start(); for (int i = 0; i < 1000; i++) Console.Write ("x"); } static void WriteY() { for (int i = 0; i < 1000; i++) Console.Write ("y"); }} The main thread creates a new thread t on which it runs a method that repeatedly prints the character “y”. Once started, a thread’s IsAlive property returns true, until the point where the thread ends. Done static void Go(){ if (! Done Done (usually!) Join and Sleep

http://www.albahari.com/threading/

Related:  C#

Data trees and C# in Grasshopper - James Ramsden Understanding how Grasshopper handles data is crucial for taking full advantage of GH’s capabilities. For collections of data, they can either be in the form of lists or trees. A list is a collection of items of data, in a particular order, but with no hierarchical structure. Here is a list of numbers:

.NET Framework 4 The .NET Framework is a development platform for building apps for Windows, Windows Phone, Windows Server, and Microsoft Azure. It consists of the common language runtime (CLR) and the .NET Framework class library, which includes classes, interfaces, and value types that support an extensive range of technologies. The .NET Framework provides a managed execution environment, simplified development and deployment, and integration with a variety of programming languages, including Visual Basic and Visual C#. The documentation for the .NET Framework includes an extensive class library reference, conceptual overviews, step-by-step procedures, and information about samples, compilers, and command-line tools. To locate the information that interests you, see the following list of main topic areas. Provides a comprehensive overview of the .NET Framework and links to additional resources.

patterns & practices Each patterns & practices offering contains a combination of written documentation and re-usable source code. Many also include a reference implementation. As the guidance is being developed it is reviewed and approved by internal Microsoft product teams and by external customers and partners. This produces a solid starting point for your application and a set of proven practices that you can follow with confidence. Many patterns & practices offerings illustrate how to incorporate multiple Microsoft products and technologies into an overall solution. C# In this tutorial, we modify the Grasshopper plugin template to add additional parameters to the spiral component. By: Zach Downey In this tutorial we look at a more steamlined approach to the build/test cycle.

C# Tutorial - Serialize Objects to a File While storing information in memory is great, there comes a time your users will have to shut your application down. This means (probably) that you will need to write information to a file at some point, because you will want to store whatever data was in memory. Today, we are going to take a look at a feature built into .NET called Serialization that makes writing and reading data structures to and from a file extremely easy. For this example, let's say I want to create a program that keeps track of all the cars my friends own. I'm going to create two objects to achieve this: Car and Owner. The Car object will store the make, model, and year of the car.

Intro to C# Scripting in Grasshopper This tutorial covers the use of the timer block to continuously execute a custom script. By: Zach Downey In this tutorial we recreate the pointAt componet and the divide curve component using C#. In this lesson, we cover control flow in your scripts. We introduce the if-else clause and also touch on the modulo % operator. Nested loops! Serialize List Tutorial A List can be serialized to the disk. We want to serialize (to a file) a List of objects. The next time the program runs, we get this List straight from the disk. We see an example of BinaryFormatter and its Serialize methods. Wrox [share_ebook] Visual Basic 2008 Programmer's Reference by Rod Stephens Category: Technical Tag: Programming Posted on 2008-03-16.

C# Tutorial - Using The ThreadPool A thread pool takes away all the need to manage your threads - all you have to do is essentially say "hey! someone should go do this work!", and a thread in the process' thread pool will pick up the task and go execute it. And that is all there is to it. Granted, you still have to keep threads from stepping on each other's toes, and you probably care about when these 'work items' are completed - but it is at least a really easy way to queue up a work item.

Hosting EXE Applications in a WinForm project Download demo project and source- 15.6 Kb Introduction Though not a common task, recently I needed to take an existing executable application and embed it into an application I was building.

Related: