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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:28:15+00:00 2026-06-15T11:28:15+00:00

How can I pass a Method2 to thread as shown in below if i

  • 0

How can I pass a Method2 to thread as shown in below if i write code as shown in below it shows an error Error

The best overloaded method match for
‘System.Threading.Thread.Thread(System.Threading.ThreadStart)’ has
some invalid arguments

   class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Main Thread : ");           
            Thread obj = new Thread(Method2);
            obj.Start();                   
            Console.ReadLine();
        }       
        private static int Method2(int a)
        {
            return a;
        }
    }

When i use the following code it works

Thread obj = new Thread(() => Method2(1));

But why it’s not working when i pass delegate object

delegate int del(int i);

del d = Method2;

Thread obj = new Thread(d);

What is the difference between above 2 , in 1st case i used Lambda expression in second case directly passed delegate object is there any thing else?

  • 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-15T11:28:16+00:00Added an answer on June 15, 2026 at 11:28 am

    The Thread constuctor takes two types of delegates, ThreadStart and ParameterizedThreadStart. To see what type of method these delegates accept you can create it and the constructor will show you, so for example,

    var parameterMethod = new ParameterizedThreadStart(...
    

    If you type the above you will see the delegate takes a function with one object as the parameter and returns void.

    void (object) target
    

    This is why your Method that takes an int will not work because the signature does not match the delegate target signature. When you wrap it in a lambada, you are actually passing in a method that takes no parameters and returns void, so the Method2 signature is not even looked at. Wrapping method calls with a lambada like this can be very useful for getting the signature to match.

    delegate void del(object obj);
    del d = () => Method2(1);
    Thread obj = new Thread(d);
    

    There is an infinite number of possible method signatures so Threads and Tasks keep it simple and say if you want to pass something, pass a single object. Since all types derive from object, this lets you pass in anything you want, then cast it later.

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

Sidebar

Related Questions

With ASP.NET MVC 1.0, .NET 3.5 and C# you can easily pass a method
You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
From a method, I can pass a struct which contains an array of integers,
When you use the Trim() method on a string object, you can pass an
I've created a wrapper function for jQuery's $.ajax() method so I can pass different
Can i pass strings as arguments during method.Invoke(objectname,object[]params) for a method of signature Getdetails(int,string,bool)
How to pass parameters to Thread.ThreadStart() method in C#? Suppose I have method called
i need to pass variables to the thread method when creating a new thread
in MongoDb I can pass a predicate to an queryable instance for example DataBase.GetCollection<BsonDocument>(entity)
In JSF 2 you can pass around ids, Strings other things that can be

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.