Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Declarative multithreading

, 13 Mar 2012 CDDL
An introduction and proof of concept code for the idea of declarative multi threading in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThreadBound
{
    /// <summary>
    /// Base class for thread bound objects that want to utilize the WasCanceled() feature of
    /// the framework.
    /// </summary>
    public class ThreadBoundObject :
        ContextBoundObject
    {
        /// <summary>
        /// Checks if the current method was cancled.
        /// </summary>
        /// <remarks>
        /// If the method is executed synchronously WasCanceled will always return false.
        /// </remarks>
        /// <returns>Returns true if Cancel was called on the IAsyncCallState-Interface of an asynchronous call.</returns>
        public bool WasCanceled()
        {
            //-- Here is no threading issue because every thread has its own version
            //   of currentMethod and therefore it is not possible to change the value
            //   from an other thread!
            if (ThreadGlobals.currentMethod != null)
                return ThreadGlobals.currentMethod.WasCanceled();
            else
                return false;
        }
    }
}

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 Common Development and Distribution License (CDDL)

Share

About the Author

gossd
Systems Engineer
Germany Germany
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 Mar 2012
Article Copyright 2011 by gossd
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid