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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:12:00+00:00 2026-05-28T00:12:00+00:00

I have an issue with a Windows Forms application that I am creating. The

  • 0

I have an issue with a Windows Forms application that I am creating. The application is supposed to be an integration testing application. Essentially, it’s supposed to test the methods that utilize lots of web services in one of my classes. I am loading the methods from the class I want to test via reflection, and am doing so like this:

private List<string> GetMethods(Type type)
{
    return (from method in type.GetMethods() where method.IsPublic &&
        method.ReturnType == typeof(void) select method.Name).ToList();
}

This returns a list of the methods from that class that have been created to test the web services and places them in a ListBox where the user can select as many methods as he/she likes. My confusion comes in here. What I would like to do is get the methods selected by the user and execute the corresponding method X amount of times (there is a text box for entering the number of times to execute a method on the form as well). I can’t figure out how to execute these methods based on the name of the method I got through reflection. I’ve tried something like this, but I know it’s not right:

private void RunMethods(Type type)
{
    var tester = new ClassToTest();
    foreach(var item in lstMethodList.SelectedItems)
    {
        foreach(var method in type.GetMethods())
        {
            if(String.Equals(item.ToString(), method.Name))
            {
                ThreadStart ts = new ThreadStart(method.Name);
                Thread thread1 = new Thread(ts);
                thread1.Start();
            }
         }
     }
}

This won’t even compile, as a ThreadStart requires a method name as a parameter. Is there any way that this is possible to do? Maybe I’m going about it wrong logically, but I’d like to create a thread for each method that needs to be run and execute that method however many times the user specifies. This is supposed to be a way of doing integration testing along with some load testing to see what the web service can handle.

  • 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-28T00:12:01+00:00Added an answer on May 28, 2026 at 12:12 am

    You can create an instance of your class using Activator.

    Then you can call one of its methods using Invoke.

    Something like this should work:

    private void RunMethods(Type type)
    {
        foreach( var item in lstMethodList.SelectedItems )
        {
            foreach( var method in type.GetMethods() )
            {
                if( String.Equals( item.ToString(), method.Name))
                {
                    MethodInfo capturedMethod = method;
                    var t = new Thread( () => ThreadMain( type, capturedMethod ) );
                    t.Start();
                }
             }
         }
    }
    
    static void ThreadMain( Type type, MethodInfo mi )
    {
        object o = Activator.CreateInstance( type );
    
        object[] parameters = new object[] { };
    
        mi.Invoke( o, parameters );
    }
    

    I’ve assumed the class being tested has a parameter-less constructor.

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

Sidebar

Related Questions

Background : I have a C# Windows Forms application that contains a Windows service
I have a Mono application with a plain-old Windows Forms form that has a
I have a Windows Forms application that was created in Visual Studio 2008 and
I have a c# Windows Forms application, using .NET 3.5. My machine environment is
I have a Windows Forms application developed using C# in .NET framework 3.5, Service
We are having an issue with our Windows forms application where it is terminating
I have a windows forms application on which I need to use a for
I'm working on a WinForms application that uses System.Windows.Forms.PrintPreviewDialog to display a Print Preview
I have a Winforms application that is working correctly on various versions of windows
We have an issue using the PEAR libraries on Windows from PHP . Pear

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.