Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2007, 7:22 AM   #11
Lesliect6
Programmer
 
Join Date: Aug 2005
Posts: 68
Rep Power: 4 Lesliect6 is on a distinguished road
Quote:
Unless your app is multi-threaded of course, because Sleep only 'sleeps' one thread so if a second thread is still working away then the cpu is still in use.
Whoops...you're right...where do you change that in project properties?

Thanks,

Leslie
Lesliect6 is offline   Reply With Quote
Old Jun 29th, 2007, 9:02 AM   #12
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,209
Rep Power: 5 grumpy is on a distinguished road
Quote:
Originally Posted by Lesliect6 View Post
Whoops...you're right...where do you change that in project properties?
If there is a project property related to developing a multithreaded application, the option you change is specific to your development environment ..... and usually only links in a library that is thread safe.

Making an application multi-threaded is more than just setting a few project options. It is also necessary to break up your code so parts can be executed on different threads, create the threads, define mechanisms to synchronise sharing of data between threads, (optionally) move threads to particular processors, handle the results when a thread terminates, etc etc.
grumpy is offline   Reply With Quote
Old Jun 29th, 2007, 9:04 AM   #13
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Threading isn't something you can turn on and off like that. I suspect the setting you're thinking of is for linking against thread safe runtime or not. At least that would be the case for native applications, but I'm not familiar enough with .NET to know if those settings still apply.

It is reasonably safe to assume that if you are not actively using multiple threads yourself then that is not the issues so that bring us back to what has already been said-

If the "quite long and complicated code" takes longer than X seconds to run then there is nothing you can do, if it doesn't then Sleep() will work if it's used correctly.

Edit - Replied same time as Grumpy so repeated some of what he said.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Jun 30th, 2007, 7:21 AM   #14
Lesliect6
Programmer
 
Join Date: Aug 2005
Posts: 68
Rep Power: 4 Lesliect6 is on a distinguished road
OK, this is getting weird. The Sleep() function does work, but only in the followng case :

#include ...

using ...

int main(array<System::String ^> ^args)
{
     Sleep(5000);

     for(...)
    {
    ...***THE CODE***
    }
}

but not in this case :

#include ...

using ...

int main(array<System::String ^> ^args)
{
     for(...)
    {
    Sleep(5000);
    ...***THE CODE***
    }
}

In the first case, it does sleep 5 seconds at 0 percent CPU power, whereas in the second it is constantly at 50 percent. What can the problem be?

Thank you,

Leslie
Lesliect6 is offline   Reply With Quote
Old Jun 30th, 2007, 8:54 AM   #15
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
Yep that is odd. In the second case it must surely at least sleep for an initial 5 seconds. If after that it never seem to sleep again it has to be that ***THE CODE*** never actually stops working so hence there isn't ever a second iteration of the for loop.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Jun 30th, 2007, 10:13 AM   #16
Lesliect6
Programmer
 
Join Date: Aug 2005
Posts: 68
Rep Power: 4 Lesliect6 is on a distinguished road
The ***CODE*** gives accurate and good results, meaning that it does iterate the number of times defined. However, as you said, it doesn't sleep, even for the first time.
Lesliect6 is offline   Reply With Quote
Old Jul 1st, 2007, 1:17 PM   #17
Eoin
Hobbyist Programmer
 
Eoin's Avatar
 
Join Date: Jun 2006
Location: Ireland
Posts: 152
Rep Power: 3 Eoin is on a distinguished road
To be honest I'm a bit stumped. And I really just don't know enough about .NET to offer alternatives but if you read this msdn link on timers I'm sure you'll be able to figure something to, there's lots of sample code.
__________________
Visit my website BinaryNotions.
Eoin is offline   Reply With Quote
Old Jul 1st, 2007, 2:25 PM   #18
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
The example that you posted should not stay at half utilization. It should drop to zero for five seconds at a time with spikes during ***THE CODE***. Have you set breakpoints or added debugging output in useful places to tell what's actually happening?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FFT DWTIB -> Optimization -> Choosing An Appropriate Run Time Sane Software Design and Algorithms 7 Dec 1st, 2006 10:40 AM
Show or hiding forms/modifying control properties ..from different a form.. cloud- C# 4 Nov 10th, 2006 10:51 AM
Form Submit Blues MegaArcon Python 3 Dec 14th, 2005 4:20 PM
.NET Timer Form closing issue MBirchmeier C# 4 Nov 21st, 2005 10:00 AM
entering data into excel from a form glevine Perl 1 Nov 18th, 2005 5:03 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC