Click here to Skip to main content
12,759,402 members (33,604 online)
Click here to Skip to main content

Stats

30.7K views
171 downloads
51 bookmarked
Posted 7 Jan 2008

Concurrent Programming - Investigating Task Messaging To Achieve Synchronization Free Inter-Task Communication

, 7 Jan 2008 CPOL
Further studies of Parallel FX.
using System;
using System.Threading.Tasks;

namespace Clifton.Concurrent
{
	public class TaskMessage
	{
		protected Task fromTask;
		protected IMessage message;

		public Task FromTask
		{
			get { return fromTask; }
		}

		public IMessage Message
		{
			get { return message; }
		}

		protected TaskMessage()
		{
		}

		public TaskMessage(Task fromTask, IMessage message)
		{
			this.fromTask = fromTask;
			this.message = message;
		}
	}

	/// <summary>
	/// The built-in message instructing the thread to stop.
	/// </summary>
	public class StopMessage : IMessage, IClonableMessage
	{
		internal static StopMessage msg = new StopMessage();

		public static IMessage Default
		{
			get {return msg;}
		}

		public IMessage DeepClone()
		{
			return msg;
		}

		protected StopMessage()
		{
		}
	}

	/// <summary>
	/// The built-in message telling the task that there are no
	/// messages.  Used when the task wants to check for messages
	/// every once in a while rather than blocking until a message
	/// is received or the task is cancelled.
	/// </summary>
	public class NoMessage : IMessage, IClonableMessage
	{
		internal static NoMessage msg = new NoMessage();

		public static IMessage Default
		{
			get { return msg; }
		}

		public IMessage DeepClone()
		{
			return msg;
		}

		protected NoMessage()
		{
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Marc Clifton
United States United States
Marc is the creator of two open source projects, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.

Marc lives in Philmont, NY.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170217.1 | Last Updated 7 Jan 2008
Article Copyright 2008 by Marc Clifton
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid