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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:24:24+00:00 2026-05-27T12:24:24+00:00

In my code im running a thread. What I need to do now is

  • 0

In my code im running a thread. What I need to do now is to pass a variable to “SayHello” method. Since it is calling in a separate thread my variables are not visible for the thread.

ThreadStart ts = new ThreadStart(SayHello);
mThread = new Thread(ts);
mThread.Start();

Im new to C# and please let me know how to do this.

  • 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-27T12:24:25+00:00Added an answer on May 27, 2026 at 12:24 pm

    this is how I pass values. First, your parameter must be a object, so you need to cast in your method. Your method must return void, if you need to return values, you can do it in many ways, volatile variables, or thread communication, etc. Then:

    string sParameters = "This is my parameter";
    Thread thrProcess = new Thread(MyMethod);
    thrProcess.IsBackgroud = true;   // only if needed
    thrProcess.Start(sParameters);   // string derives from object
    

    And in your method:

    void MyMethod(object param)
    {
        string sParameterValue = (string)param;
    // Now you can work with sParameterValue
    }
    

    If you need to pass more than one variable, then create a class and assign your values to properties, and cast in your method, but there are other ways to archive this. Hope this helps. If you need more info, chech this
    link: Threading in C#

    Good luck!

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

Sidebar

Related Questions

I have a thread in my application that is running code that can potentially
I'm trying to execute a long-running piece of code in a background thread and
I'm running a process in a separate thread with a timeout, using an ExecutorService
Here's the situation, I have a thread running that is partially controlled by code
I'm using vb.net 2005, I've got the following code running a thread to download
I have code running in an iPhone application I am developing. Basically, the code
I have the following code running on my Android device. It works great and
I've been refactoring some code running on a simple LAMP box on my network.
I have two pieces of C++ code running on 2 different cores. Both of
Sorry I cannot post any source code... I have a code running a master/slave

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.