Click here to Skip to main content
12,241,814 members (24,309 online)
Click here to Skip to main content

Stats

30.4K views
746 downloads
136 bookmarked
Posted

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 ThreadBound;
using System.Threading;

namespace FormsTest
{
    [ThreadBound(ThreadBoundAttribute.ThreadBinding.WorkerContext)]
    class NumberWorkerC : ThreadBoundObject, IDisposable
    {
        public delegate void NewNumberHandler(int number);
        public event NewNumberHandler NewNumber;

        [AsyncThreaded]
        public IAsyncCallState CreateNumbers(int limit, int delay)
        {
            for (int i = 0; i <= limit; i++)
            {
                Thread.Sleep(delay);
                if (NewNumber != null)
                    NewNumber(i);

                if (WasCanceled())
                    break;
            }

            return null;
        }

        public void Dispose()
        {
        }
    }
}

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

You may also be interested in...

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