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#C# & MVCC#Informationvoldemar_d

Support Jesse Dietrichson creating Programming Tutorials Programming is what I want to do with my life. I began programming from a very young age, and once I started I couldn't stop. Most of what I know has been self taught. I've spent countless hours over the years, reading every programming book I could get my hands on. I specialize in C#, C++ and Java, and I am always trying to learn more. I am continuing my programming career as a computer science major at Farmingdale State College. LINQ Secrets Revealed: Chaining and Debugging LINQ has the capabilities of providing a great productivity boost. LINQ Chaining is particularly powerful magic, giving your code greater clarity and brevity. Using it, and debugging it, can be tricky without the right tools and techniques, but Michael is on hand to explain and make suggestions. This article is for .NET developers who have not used LINQ, LINQ users who have not used LINQPad, and LINQPad users who have not used LINQPad Visualizer. (Some familiarity with LINQ is assumed though.)

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:

Parameter passing in C# Many people have become fairly confused about how parameters are passed in C#, particularly with regard to reference types. This page should help to clear up some of that confusion. If you have any suggestions for how it can be made clearer, please mail me. Microsoft also has a good page about this topic (which I believe uses exactly the same terminology as this page - let me know if they appear to disagree). Note: Lee Richardson has written a complementary article to this one, particularly for those who learn well with pictures. Basically it illustrates the same points, but using pretty diagrams to show what's going on. Serial Port Communication Tutorial With C# Examples - CodeSamplez.com In today’s programming tutorial, I am going to describe some basics about how we can perform serial port communication from our C#.NET applications. Serial communications can be done via either direct to physical serial port connected to the computer or via a USB to serial converter interface. If the device do require a serial port and your computer don’t have any, you can make use of such converters easily.

C# Best Practices - Dangers of Violating SOLID Principles in C# As the process of writing software has evolved from the theoretical realm into a true engineering discipline, a number of principles have emerged. And when I say principle, I’m referring to a feature of the computer code that helps maintain the value of that code. Pattern refers to a common code scenario, whether good or bad. For example, you might value computer code that works safely in a multi-threaded environment. You may value computer code that doesn’t crash when you modify code in another location.

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! Designing and implementing a Data Warehouse Part I Introduction Business Intelligence has become a buzzword in recent years as a support to decision making. Today we can find several database systems which include data warehousing, online analytical processing (OLAP), and data mining technologies. Data warehousing provides an efficient storage, maintenance, and retrieval of data.

Reducing Memory Usage in Unity, C# and .NET/Mono Unity on iOS uses an early version of Mono’s heap manager. This manager doesn’t do packing, so if you fragment your heap, it’ll just grab a new one for you. I am under the impression the Unity boffins are working on a new heap manager to get around this problem, but for now a game with no memory leaks can end up consuming ever-increasing amounts of memory. C# is a fun language that allows you to quickly write powerful code without sacrificing readability. However the downside to this is that writing natural C# code produces a lot of garbage collection. The only way around this is to eliminate or reduce your heap allocations. Serial Comms in C# for Beginners Download source Introduction Serial Communication between PCs is always seen as the starting point. My first piece of serial comms code was a University assignment getting two PC’s, then three, then… you get the idea talking on (what I now know to be) an RS422 with its pair of cables using Borland's Turbo C++ for DOS. Time passed I graduated (somehow!) and I got to be a Design Engineer in the ‘real’ world.

Related: