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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:08:53+00:00 2026-06-09T20:08:53+00:00

I know how to start a function in x seconds, its something like this

  • 0

I know how to start a function in x seconds, its something like this:

private Timer timer1; 
public void InitTimer()
{
    timer1 = new Timer();
    timer1.Tick += new EventHandler(timer1_Tick);
    timer1.Interval = 2000; // in miliseconds
    timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
    function1();
    function2();
    function3();
}

The problem here: The functions cannot run at the same time. Function2 can only run if Function1 is done. But I want them running at the same time. Thats why I could do this:

private void timer1_Tick(object sender, EventArgs e)
{
   Parallel.Invoke(
     () => Function1(),
     () => Function2(),
     () => Function3()
   );
}

Is this the smartest way to do it in c#? What I dont understand with Parallel.Invoke: what if my timer is set for 5 sec and after 5 sec function1,2 and 3 are not done but I call them all again. Do I start these functions in a new thread? Are there after some calls x-threads running function1() (at the same time)? Wondering is that really healthy.

If somebody would like to get more information: function1 is just there to copy file x from folder a to b, function2 is only there to read all files from folder b and save the information and function3 is only there to check the connection and if there is a connection send the appropriate file to somebody.

Any suggestions to the code? Thank you

  • 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-06-09T20:08:54+00:00Added an answer on June 9, 2026 at 8:08 pm

    Use System.Threading.Timer to schedule the callback on a ThreadPool thread, so you don’t need to create a new task. It also allows you to control the intervals to prevent the overlap of callbacks.

    // fired after 5 secs, but just once.
    _timer = new System.Threading.Timer(Callback, null, 5000, Timeout.Infinite);
    
    // on the callback you must re-schedule the next callback time;
    private void Callback(Object state) {
       Function1();
       Function2();
    
       // schedule the next callback time 
       _timer.Change(5000, Timeout.Infinite);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I start know this: I am extremely new to Java and programming. How
I already know how to start a one new activity when you click a
I would like to know how to start and code a thread manager for
I feel like I should know this but I've been stumped for hours now
Consider this pair of functions in C#: void func1() { DispatcherTimer tmr = new
1) I know the start point of the arrow and I know the endpoint.
if you know the start and end positions in string from where to begin
Possible Duplicate: How to know if Process.Start() is successful? I have a process similar
I am struggling to know where to start when trying to assign ranks to
I want to start web developing with java. I don't know how to start,

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.