Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:57:48+00:00 2026-06-11T15:57:48+00:00

Its a follow up of this question. https://stackoverflow.com/questions/12260170/how-to-make-a-threadpool-to-be-nonblocking I have achieved it using interface.

  • 0

Its a follow up of this question.

https://stackoverflow.com/questions/12260170/how-to-make-a-threadpool-to-be-nonblocking

I have achieved it using interface. I have made it nonblocking using Action/deleages & using interfaces.. Is there any other way available in .net that I can make the below piece of code nonblocking??? Interface implementation is below. At any point of time I should have only three functions Main, FuncA & FuncB

if some one could kindly help. it will be really appreciated. Thank you.

using System;
using System.Threading;

namespace ConsoleApplication2
{
    public interface IOperation
    {
        void CallBack(int i);
    }

    public class FuncBCalculation
    {
        public int N { get { return _n; } }
        private int _n;

        public int MyValue { get; set; }
        public FuncBCalculation(int n)
        {
            _n = n;
        }

        // Wrapper method for use with thread pool.
        public void FuncB(object context)
        {
            IOperation FuncBcallback = (IOperation)context;
            Thread.Sleep(5);
            MyValue = _n + 2;
            FuncBcallback.CallBack(MyValue);
        }
    }

    public class ActualClass : IOperation
    {
        int Finalvalue = 0;
        public static IOperation MainThreadCallBack { get; set; }

        public void FuncA(int input, int i, IOperation callback)
        {
            input += 1;
            var f = new FuncBCalculation(input);
            MainThreadCallBack = callback;
            IOperation op = new ActualClass();
            ThreadPool.QueueUserWorkItem(f.FuncB, op);

        }

        //Method for callback operation
        public void CallBack(int i)
        {
            Finalvalue = i + 3;
            if (MainThreadCallBack != null)
                MainThreadCallBack.CallBack(Finalvalue);
        }
    }


    public class ThreadPoolExample : IOperation
    {
        static void Main()
        {
            ActualClass actualCall;
            const int TotalLoopCount = 1000;
            int input = 11;
            Console.WriteLine("launching {0} tasks...", TotalLoopCount);
            for (int i = 0; i < TotalLoopCount; i++)
            {
                IOperation op = new ThreadPoolExample();
                actualCall = new ActualClass();
                actualCall.FuncA(input, i, op);
            }
            Console.ReadKey();
        }

        //Method for callback operation for the main thread
        public void CallBack(int i)
        {
            Console.WriteLine("The final Result is {0}", i);
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:57:50+00:00Added an answer on June 11, 2026 at 3:57 pm
    public class State
    {
        public int input { get; set; }
        public int result { get; set; }
        //public static int ThreadCount { get; set; }
        public bool FuncBSignalON { get; set; }
        //public static bool FuncAThreadON { get; set; }
       //public int TotalLoopCount { get; set; }
        //public int ThreadID { get; set; }
    }
    
    
    public class MainClass
    {
        public static void FuncB(Object stateObject)
        {
            State state = stateObject as State;
            state.input += 2;
            state.FuncBSignalON = true;
            ThreadPool.QueueUserWorkItem(new WaitCallback(FuncA), state);
        }
    
        public static void FuncA(Object stateObject)
        {
            State state = (State)stateObject;
            if (!state.FuncBSignalON)
            {
                state.input += 1;
                ThreadPool.QueueUserWorkItem(new WaitCallback(FuncB), state);
            }
            else
            {
                state.result = state.input + 3;
                //FinalResult.Add(state.result);
                string[] stateResult = new string[1];
                stateResult[0] = state.result.ToString();
                //State.ThreadCount--;
                Main(stateResult);
            }
        }
    
        static void Main(string[] args)
        {
            if (args.Count() == 0)
            {
                int TotalLoopCount =1000; 
                for (int i = 0; i < TotalLoopCount; i++)
                {
                    State FuncAstate = new State();
                    FuncAstate.input = 11;
                    //FuncAstate.TotalLoopCount = TotalLoopCount;
                    //State.ThreadCount++;
                    ThreadPool.QueueUserWorkItem(new WaitCallback(FuncA), FuncAstate);
                }
            }
            else
            {
              Console.WriteLine(args[0]);
            }
            Console.ReadKey();
        }
    
    }
    

    Got it at last.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've read this: https://stackoverflow.com/questions/631850/how-do-you-name-your-many-to-many-relationship-tables But my question is a little different. I'm just wondering
I'm trying to follow http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/ And have created a very simple example http://jsfiddle.net/6wbZQ/ It's
I have seen few questions similar to this one, but I wanted to make
This is a follow-up of my question . I am using nltk to parse
This question is a follow up on this question . I am using the
This is somewhat of a follow-up question to this question . Suppose I have
This question is a follow-up to this . I can't seem to change the
So this question is a sort of follow on from here ( how to
This is a follow-up to a question I asked a few weeks back. The
I know this question is very similar to this one, but I feel its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.