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 6637685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:20:39+00:00 2026-05-25T23:20:39+00:00

What I am trying to do is be able to pass a function reference

  • 0

What I am trying to do is be able to pass a function reference to another function and have it used as a callback method for a System.Threading.ThreadPool.QueueUserWorkItem.

See in method D() the ‘Any’ parameter.

I need to be able to pass the callback method pointer or reference for the ‘Any’ parameter. I can’t use a delegate, because that would need to be static, is that correct?

Any ideas?

    private void A() { /*code*/ }

    private void B() { /*code*/ }

    private void C(int i)
    {
        switch(i)
        {
            case 1:
                D(A());
                break;
            case 2:
                D(B());
                break;
            default:
                break;
        }
    }

    private void D(type? Any)
    { 
        System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(Any));
    }
  • 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-05-25T23:20:39+00:00Added an answer on May 25, 2026 at 11:20 pm

    I think this will do what you want, but WaitCallback delegates take an object as a parameter.

            private void A(object state)
        {
            // does one thing
        }
    
        private void B(object state)
        {
            // does a different thing
        }
    
        private void C(int i)
        {
            switch (i)
            {
                case 1:
                    D(new System.Threading.WaitCallback(A));
                    break;
                case 2:
                    D(new System.Threading.WaitCallback(B));
                    break;
                default:
                    break;
            }
        }
    
        private void D(System.Threading.WaitCallback worker)
        { 
            System.Threading.ThreadPool.QueueUserWorkItem(worker);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass a function reference from JavaScript in a WebView, so my
I am trying to allow very primitive customization based on being able to pass
I am trying, in vain it seems, to be able to pass additional parameters
I'm trying to be able to have a global exception capture where I can
I'm trying to devise a method that will be able to classify a given
I am trying to pass an object to a javascript function which should trigger
I have a List(Of AddlInfo) with AddlInfo being an object. I'm trying to pass
I would like to pass a function as a template argument to another function
i am trying to use my parent function to have a value. this is
So I'm trying to learn how to pass arrays through a function, so that

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.