Multithreading with Netduino and .NET Microframework

In this post, we’ll show you how to multithread with Netduino and .NET Microframework.

First, we’ll use the standard way:

public class Program
{
	public static void Main()
	{
		Thread someThread = new Thread(SomeThreadMethod);

		// Start the thread execution
		someThread.Start();

		// Main thread code continues
		...

		// Exiting main thread will stop someThread
	}

	private static void SomeThreadMethod()
	{
		// The thread's code
		...
	}
}

In this next example, we will execute the thread and suspend the main thread until we resume it:

public class Program
{
	private static Thread mainThread;

	public static void Main()
	{
		// Get handle to main thread
		mainThread = Thread.CurrentThread;

		Thread someThread = new Thread(SomeThreadMethod);

		// Start the thread execution
		someThread.Start();

		// Suspend main thread execution
		mainThread.Suspend();

		//Following code will be executed after main thread is resumed
		...
	}

	private static void SomeThreadMethod()
	{
		// The thread code
		...

		// Resume main thread
		mainThread.Resume();
	}
}

Read the rest of the post here: http://www.codeproject.com/Articles/795829/Multithreading-with-Netduino-and-NET-Microframewor

Leave a Reply

Your email address will not be published. Required fields are marked *