?
Solved

c# pause execution

Posted on 2013-05-17
9
Medium Priority
?
343 Views
Last Modified: 2013-05-18
Ok, ok, i know this should be a scheduled service, but its got too much UI. I want an app to execute a proc from 9-5pm, but be running all the time so it starts every day at 9 and stops and 5pm.
If i use Thread.Sleep(10mins) say, and check the time in a loop would that be ok in terms of reliability (e.g the thread won't get aborted by the runtime if it gets bored) and system resouces? (although aren't extremely limited  but it shouldn't soak up as much than if it was performing higher maths calcs to fill time for example, shouldn't it?)
What other/better way is there?
0
Comment
Question by:Silas2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39176206
Noting wrong with polling at longer inervals.  Are you having the thread stopped when you put it to sleep for really long periods (like 16 hours at night)?
0
 

Author Comment

by:Silas2
ID: 39177056
Re: "...Are you having the thread stopped when you put it to sleep for really long periods ...? yes, well sleep(ed) if that is the same thing, that was the idea.
Re mroonal: Those links are to SQL server utilities aren't they? This is just .Net (WPF) app. What use are they?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 39177235
As far as I know, a thread that sleeps for a very long period of time is in no danger of being discarded.
0
 

Author Comment

by:Silas2
ID: 39177263
Have you any idea of the timing mechansim for sending them to sleep/reawaken if you're doing longer periods? (actually i think 20min polls would be ok)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39177269
Just create a TimeSpan() with your desired duration and pass that to Sleep():

    System.Threading.Thread.Sleep(TimeSpan.FromMinutes(20));

If you want to wake up at a specific time, then compute that time and subtract Now() from it:

            // figure out when the next 9:00 am is:
            DateTime dt = DateTime.Today.AddHours(9);
            if (DateTime.Now > dt) // past 9:00 am already...
            {
                dt = dt.AddDays(1); // ...get tomorrow's 9:00 am
            }
            System.Threading.Thread.Sleep(dt.Subtract(DateTime.Now));
0
 

Author Comment

by:Silas2
ID: 39177280
Sorry, I didn't mean that.
I just wondered if the thread had an inbuilt event listener so that the processor would reawaken it at the end of the timespan, or does it sort of 'count-down' from when you start the sleep, so it never really goes to sleep, but just quietly counting down, or....? I was trying to think of some more mechanisms it could use.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39177289
To be honest, I'm not sure what it's using under the hood to implement its Sleep() mechanism.  Whatever it is, it uses little to no CPU cycles...
0
 

Author Comment

by:Silas2
ID: 39177390
Sorry, I'm just a bit interested after being probably one of the only people to do the exam in Microsoft Workflow Foundation 3.5, only to find it was killed off completely the next day! I never bothered with it after that. It was all about this, sleeping processes brought back to life i mean.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question