C# Code Snippets Sending and Receiving Data From a Thread

C# Sending and Receiving Data From a Thread

In this tutorial, we will see how to pass/get data to/from a thread in C#. To pass data into the thread we will simply pass it as an input parameter to the method that is being started as a new thread. To get the data from the thread a delegate callback method will be used. First, we will make a regular method that takes in an input parameter. Then we will make a delegate and make it point to this method. Finally, the delegate will be passed as an input parameter to the method that is being started as a new thread. When the child thread is done executing it will call the callback method that is located in the main thread and pass it the result as an input parameter. This is how we will be able to get the result from the child thread back into the main one.

C# Code Snippets threads and multithreading

C# Threads and Multithreading

In this tutorial, we will take a look at threads in C#. To explain what a thread is let’s first start off with the explanation of what a process is. A process is an instance of your application. The OS will assign it a chunk of virtual memory, execution context(program counter, registers, PID, …) and resource handles.

C# Code Snippets Events

C# Events

In this tutorial, we will take a look at events in C#. A class(subscriber class) can subscribe to an event of another class(publisher class). The publisher class notifies the subscriber class every time the event occurs. This works by using delegates. The subscriber will pass its delegate to the publisher class to “make a subscription” to its event. When the event occurs the publisher will call the delegate(callback method) that was provided to it by the subscriber when it “subscribed” to the event. This is how (for example button press event) events work in .NET. This principle of operation is also called the observer pattern.

C# Code Snippets Delegates

C# Delegates

In this tutorial, we will take a look at delagates in C#. A delegate is a pointer to a method(basically an indirect call to the method). Delegates can be passed as input parameters to other methods. A benefit of this is that it provides flexibility. Such a method can then use the passed in delegate to call another method(callback method). This is actually the way events work.

DIY Quiet Air Compressor

DIY Quiet Air Compressor

In this post, I will show my DIY quiet air compressor. I took the compressor from an old fridge and used an old whipped cream dispenser as an air tank. The compressor is very quiet and can thus be kept indoors(under my table in fact). The air capacity isn’t the greatest but it’s good enough for my needs(doing some pneumatics experiments, solder dispenser, …). The air pressure, however, can easily get up to 8 bar(around 120 psi). In addition to compressed air, you also get a vacuum line. You could, for example, use that for making a vacuum chamber or a vacuum pick up tool.

DPS3003 DIY Power Supply Assembled 2

DPS3003 DIY Portable Lab Power Supply

In this post, I will show my DIY portable power supply. The PSU uses the DPS3003 module. This module is rated for voltages from 0-32V and currents from 0-3A. You can get other models with higher or lower voltage/current ratings. The input voltage, however, must be in the range of 6-40V and your maximum output voltage is limited to your input voltage. In my case, the battery provides around 16V to the input so the output voltage can’t go higher than that.