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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:46:37+00:00 2026-05-27T21:46:37+00:00

I am trying to start a new thread and pass an argument to one

  • 0

I am trying to start a new thread and pass an argument to one of my methods. The argument is a List<string> and contains about 20 string items. I can pass the array fine using the following code:

List<string> strList = new List<string>();

Thread newThread = new Thread(new ParameterizedThreadStart(Class.Method));
newThread.Start(strList);

My Method is defined as:

public void Method(object strList)
{
//code
}

My question then is how can I run a foreach loop through each string that is contained in this object?

  • 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-27T21:46:38+00:00Added an answer on May 27, 2026 at 9:46 pm

    Three options:

    • Use ParameterizedThreadStart as you are, and cast within the method:

      public void Method(object strList)
      {
          List<string> list = (List<string>) strList;
          // Use list here
      }
      
    • Use an anonymous function to capture the variable in a strongly typed way, and call a strongly-typed method from the anonymous function:

      List<string> strList = new List<string>();
      ThreadStart action = () => Method(strList);
      new Thread(action).Start();
      
      ...
      
      public void Method(List<string> list)
      {
          // Use list here
      }
      
    • Use a higher-level abstraction such as the Task Parallel Library or Parallel LINQ instead; depending on what you’re doing, this may make things simpler.

    If you do want to start a new thread, I’d use the second approach – keep the “dirtiness” localized to the method starting a new thread. Any of these approaches will work though. Note that if you had more than one piece of information to pass to the new thread, the second approach ends up being simpler than creating a Tuple and unpacking it.

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

Sidebar

Related Questions

I am trying to start a new thread in VB.NET and I'm having syntax
I'm trying to use the BackgroundWorker class to start a new thread which loads
I am trying to start a method from my main() as a new thread
I am trying to start a new MVC project with tests and I thought
I'm trying to start a new ASP.NET Web Application Project using Visual Studio 2008.
I am trying to start a new project (asp.net MVC) and I would like
I'm trying to start a new struts 2 project using maven (struts2 blank archetype)
I'm trying to start a service that has a argument that specifies a port
How would i pass some parameters to a new thread that runs a function
I'm trying to start new activity by button click. Main Activity code: public class

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.