C Sharp multithreading examples

C# Threading Example On the execution of the thread, either of the static and non-static methods can be called by passing the method name in the constructor of ThreadStart class. Example 1: Static Method: using System; using System.Threading; public class Example { public static void thr() { for (char i = ‘a’; i < ‘g’; … Read more

Categories C#

C Sharp Main Thread

C# Main Thread Inside a process, the main thread is the first created thread which starts first and ends at last. Example: using System; using System.Threading; public class Example { public static void Main(string[] args) { Thread x = Thread.CurrentThread; x.Name = "Hello"; Console.WriteLine(x.Name); } }using System; using System.Threading; public class Example { public static … Read more

Categories C#

C Sharp Thread class

C# Thread class C# Thread class is found in the System.Threading namespace, to facilitate properties and methods to create and control threads. C# Thread Properties: The most common properties of the Thread class are listed below: Property Uses CurrentThread To get the instance of currently running thread. IsAlive To determine whether the current thread is … Read more

Categories C#

C Sharp Thread Life Cycle

C# Thread Life Cycle A thread in C# has a life cycle, which starts when the instance of the System.Threading.Thread class is created, and it ends when the task execution of the thread is completed. In C#, the life cycle of a thread has the following states: Unstarted Runnable (Ready to run) Running Not Runnable … Read more

Categories C#

C Sharp Multithreading

C# Multithreading The process in which multiple threads work simultaneously to achieve multitasking is called Multithreading in C#. Since multiple tasks can be executed at a time through multithreading in C#, thus it saves time. The System.Threading namespace is used in C# to create a multithreaded application. System.Threading Namespace: Various classes and interfaces are present … Read more

Categories C#

C Sharp Anonymous Functions

C# Anonymous Functions A function without a name is known as an anonymous function. Anonymous functions are of two types in C#: Lambda Expressions Anonymous Methods C# Lambda Expressions: An anonymous function used to create delegates is called lambda expressions in C#. To create local functions to be passed as an argument, a lambda expression … Read more

Categories C#

C Sharp Reflection

C# Reflection A process to get metadata of a type at runtime is called reflection in C#. The required classes for reflection are found in the System.Reflection namespace. Some of these classes are: Type MemberInfo ConstructorInfo MethodInfo FieldInfo PropertyInfo TypeInfo EventInfo Module Assembly AssemblyName Pointer etc. The classes to emit metadata are found in the … Read more

Categories C#

C Sharp Delegates

C# Delegates Being a reference to the method, a delegate in C# works like a function pointer in C and C++. As compared to a function pointer, a delegate in C# is objected-oriented, secured and type-safe. Only the method is encapsulated by a delegate in C# for the static method. While, both the method and … Read more

Categories C#

C Sharp Generics

C# Generics To define the classes and methods with placeholder or to create general purpose classes and methods, the concept of Generic is used in C#. At the compile time, the placeholders are replaced with specified type by the C# compiler. The angle <> brackets are used for the declaration of a generic class or … Read more

Categories C#

C Sharp SortedList

C# SortedList<TKey, TValue> The SortedList<TKey, TValue> class is used to store the values in ascending order based on the key as an array of key/value pairs. Found in the System.Collections.Generic namespace, the C# SortedList<TKey, TValue> class contains unique keys only, thus the stored elements can be easily searched or removed using the key. The SortedList<TKey, … Read more

Categories C#