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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:54:22+00:00 2026-05-16T21:54:22+00:00

Hi how do i call System.Reflection.MethodInfo.Invoke() with paramters with threads. For instance.. Say I

  • 0

Hi how do i call System.Reflection.MethodInfo.Invoke() with paramters with threads.

For instance..

Say I have a method that allows you to pass in a string that represents a
class name and calls corresponding class method dynamically , now i want to
call this Methodinfo.invoke with threads ,I have no idea how to do this since i am calling invoke with paramter . Code snippet given meblow . Thank you for your help

Type classType = objAssembly.GetType("MyClassName");
object obj = Activator.CreateInstance(classType)
bject[] _objval = new object[3]; 
object[] parameters = new object[] { _objval };
MethodInfo mi = classType.GetMethod("MyMethod");
mi.Invoke(obj, parameters);  // <---**How do i call this with threads.. ????**
  • 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-16T21:54:23+00:00Added an answer on May 16, 2026 at 9:54 pm

    Since you’re wanting to create a new thread with System.Threading.Thread rather than make the call on an existing UI thread or threadpool thread, first thing to notice is that with System.Threading.Thread you can use either a ThreadStart or ParameterizedThreadStart delegate.

    You do want parameters to your thread’s main method, but ParameterizedThreadStart only allows an object, which forces you to cast it to the required type. So we’ll just use a closure to get all the arguments passed across in a type-safe way.

    public void InvokeOnNewThread(this MethodInfo mi, object target, params object[] parameters)
    {
         ThreadStart threadMain = delegate () { mi.Invoke(target, parameters); };
         new System.Threading.Thread(threadMain).Start();
    }
    

    Example usage:

    mi.InvokeOnNewThread(obj, parameters);
    

    If you’re working with .NET 2.0, then take out the keyword this from the parameter list and call like:

    InvokeOnNewThread(mi, obj, parameters);
    

    This will discard any return value, but so did the unthreaded example in your question. If you need the return value leave a comment.

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

Sidebar

Related Questions

It is said that fork system call creates a clone of the calling process,
While following path for wait system call, noticed that before calling do_wait_thread we get
I have a program which does a system call: latex somefile.latex This runs ok,
I need to call a method with ref-arguments through a RealProxy. I have isolated
is it possible to call with reflection a method with explict type argument <S>
I am using Reflection.Emit to make a exe. I have come so far that
I'm trying this: Type ThreadContextType = typeof(Application).GetNestedType(ThreadContext, System.Reflection.BindingFlags.NonPublic); MethodInfo FDoIdleMi = ThreadContextType.GetMethod(FDoIdle, BindingFlags.NonPublic |
All, I have a number of C# DLLs that I want to call from
I am trying to call a class method through reflection. public class A {
When I try to call System.IO.File.Encrypt() on an existing file, it throws a generic

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.