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

  • Home
  • SEARCH
  • 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 971905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:02:19+00:00 2026-05-16T03:02:19+00:00

I am trying to get a thread working in C# to reset the time

  • 0

I am trying to get a thread working in C# to reset the time and run another function alongside it. The code I have is:

Thread loopTime = new Thread(this.someFunction);
loopTime.Start();

for (int i = 0; i < 20; i++)
{
    ChangeTimeFunction(someTime);
    Thread.Sleep(200);
}

I am getting a threading error if I pass in this.SomeFunction(). This cannot be used according to Visual Studio. I could have the for loop as a thread but I do not know how to pass in the variable someTime.

Is there a way to either pass the variable into the loop if it was a function or call the for loop from within the function.

Thanks for any help.

UPDATE:

someFunction is a recorded methods using Visual Studio. This cannot be used outside the main thread. I would need to put the for loop inside the thread I am creating. Does any one know how to do this?

Thanks

  • 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-16T03:02:20+00:00Added an answer on May 16, 2026 at 3:02 am

    Is there a way to either pass the
    variable into the loop if it was a
    function or call the for loop from
    within the function.

    .NET has two delegates for starting threads. The first is ThreadStart, which just calls a method with no arguments.

    The second is ParameterizedThreadStart, which calls a method with a single object as a parameter.

    C# will implicitly create a ParameterizedThreadStart delegate if you pass a method in the Thread constructor that has an object argument. You then send an object to it using the thread’s .Start(Object) method.

    For example, to make the for loop a thread, assuming someTime is a DateTime and including a cast to that effect:

    Thread loopTime = new Thread(someFunction);
    loopTime.Start(someTime);
    
    public void someFunction(object someTime) {
        for (int i = 0; i < 20; i++)
        {
            // Note the cast here... I assumed it's a DateTime
            ChangeTimeFunction((DateTime) someTime);
            Thread.Sleep(200);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a C++ extension for python using swig. I've followed the
I'm trying to write test harness for part of my Android mapping application. I
I'm trying to build a Chrome browser extension, that should enhance the way the
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME
I am trying to load a html page through UIWebview.I need to disable all
I am trying to understand the practical difference during the execution of a program
I am playing with TFS 2010, and am trying to setup a build process
I have several USB mass storage flash drives connected to a Ubuntu Linux computer

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.