|
Hi dear,
I created a thread.
But when I start the thread CPU load become 100%.
I use these code.
void CEventLine::BeginThread()<br />
{<br />
m_isRunning = TRUE;<br />
AfxBeginThread(ThreadStart,this,THREAD_PRIORITY_LOWEST);<br />
}<br />
<br />
UINT CEventLine::ThreadStart(LPVOID pParam)<br />
{<br />
CEventLine* pEventLine = (CEventLine*)pParam;<br />
if (pEventLine == NULL || !pEventLine->IsKindOf(RUNTIME_CLASS(CEventLine)))<br />
return 1;
<br />
while(m_isRunning == 1)<br />
pEventLine->Start();<br />
<br />
return 0;
}<br />
<br />
void CEventLine::Start()<br />
{<br />
}<br />
CEventLine is a CDialog based class.
Thank you in advance.
|
|
|
|
|
It's no great shock that the CPU load is 100%.
After all...
while (m_isRunning == 1)
pEventLine->Start ();
...
}
void CEventLine::Start ()
{
}
simply calls Start again and again and again... with no pause for "breath". It would be the same
if you put this code in your main thread. You have a few choices...
a) Put up with it. Assuming this is only for a brief duration.
b) Put up with it, but make it less of a nuisance. I've not used MFCs threads, and MFC is poor at sharing,
but you can lower thread priority to make other threads more responsice.
DWORD dwID;
hScanThread = ::CreateThread (NULL, 0, DoScan, this, CREATE_SUSPENDED, &dwID);
if (hScanThread == NULL)
{
DWORD dwError = ::GetLastError ();
} else
::SetThreadPriority (hScanThread, THREAD_PRIORITY_HIGHEST);
c) Put a delay (sleep) between each iteration of the loop. This would have to be short.
d) Some other tactic depending on the contents of CEventLine::Start () .
Iain.
|
|
|
|
|
Choice e) might be let the thread naturally relinquish the CPU by blocking on an I/O or message queue, for example. Depending on how often/long it blocks, this may be enough.
Brad
|
|
|
|
|
True, but then it may not respond to the "quit" flag.
Then again, waiting on multiple objects (the first of which is a KILL, DIE, DIE! event)
is the way I usually go. But with less dramatic variable names.
Iain
|
|
|
|
|
Sleep(0) is perfect here.
You can be nice to the system by simply using your time slice to make *one* check of the flag
and then turning over control to another thread.
Although typically I would argue against using a flag and using an appropriate synchronization
object instead.
|
|
|
|
|
Hi !
We just started to use WinCVS with Visual Studio 6 for our new project, but we don't have any experience with it. We made it work, but I would like to know if someone uses WinCVS as well.
What I'd like to know is what to do with the .obj files. When I update my project from the server, the .cpp and .h files are usually updated correctly, but the .obj, as binaries, are usually a mess, and I just have to rebuild all, which takes time.
How do you guys work ? Do you put your obj files into CVS ?
Thanks for sharing your experience !
Jerome
|
|
|
|
|
Why on earth would you put obj files in CVS?
Just put the stuff that isn't re-created automagically there.
(To add binaries you need to mark them as just that or else CVS will corrupt them).
|
|
|
|
|
Stefan Pedersen wrote:
Why on earth would you put obj files in CVS?
Well, when we first decided to use CVS, we didn't want to put obj files in it, but if we don't, each time I update my local project, I have to rebuild all, which takes a long time. How did you managed to solve this problem ?
Thanks for your answer !
Jerome
|
|
|
|
|
You shouldn't need to rebuild all.
Only the files needed should be rebuilt (you seldom update the whole project).
I would check the clock on all the computers used for devel and CVS.
Something seems a bit fishy...
|
|
|
|
|
Maybe this page can help you?
Info: (cvs) Binary howto
It talks about using the -kb option when adding a file to the repository.
|
|
|
|
|
Hello,
I know there is function that escapes an URL (for example transforms "bla bla" to "bla%20bla")...
What was its name?
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
UrlCanonicalize
Takes a URL string and converts it into canonical form.
And there was me thinking it mean promoting to sub-bishop...
Iain.
|
|
|
|
|
Hmm, I couldn't find that function... it's in the shlwapi.lib file, but I don't have any header file that contains the function declaration...
Perhaps I need latest platform sdk...
Thanks for your reply!
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/path/UrlCanonicalize.asp
|
|
|
|
|
Would you believe... UrlEscape() .
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hmm, I couldn't find that function... it's in the shlwapi.lib file, but I don't have any header file that contains the function declaration...
Perhaps I need latest platform sdk...
Thanks for your reply!
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/shlwapi/path/urlescape.asp
|
|
|
|
|
Hi,
I was wondering if someone could help me disable a menu option.
Thank you for your help.
|
|
|
|
|
If you're using MFC, look up EnableMenuItem in the CMenu class documentation.
If you're not using MFC, just look up EnableMenuItem.
Jason Henderson "I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it."
- Jack Handey
|
|
|
|
|
Hi Jason,
I don't have MSDN installed on this computer, I only remember off the top of my head its something like :
EnableMenuItem((i think its the menuID?), Flags);
Can you or someone shed some light to get this done with MFC?
Thank you for your help!
|
|
|
|
|
Jay Hova wrote:
don't have MSDN installed on this computer
You can find it online at msdn.microsoft.com[^].
It is the one most valuable resource you need as a programmer. BTW - Your compiler came with a copy of MSDN.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
BOOL EnableMenuItem(
HMENU hMenu, // handle to menu
UINT uIDEnableItem, // menu item to update
UINT uEnable // options
);
or
// MFC CMenu
UINT EnableMenuItem(
UINT nIDEnableItem,
UINT nEnable
);
Jason Henderson "I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it."
- Jack Handey
|
|
|
|
|
I have only been programming for a month, so please be patient.
right now i am using the code i found on the msdn.microsoft.com site
CMenu* mmenu = GetMenu();<br />
CMenu* submenu = mmenu->GetSubMenu(0);<br />
submenu->EnableMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
I get the error that GetMenu doesn't take 0 parameters?
Can someone tell me whats wrong. I used similar code if not the same, to get a couple other menu options checked/unchecked and it worked fine. Don't understand why it doesn't work.
Oh yeah, I have no idea why msdn is not installed on this computer? its not my own.
|
|
|
|
|
You are mixing CWnd::GetMenu/CWindow::GetMenu and ::GetMenu
Win API: HMENU GetMenu( HWND hWnd );
From your mainframe class try calling GetMenu()...
Brian
|
|
|
|
|
I am calling this from my main class...
I don't get it. I have almost the same exact code right beneath it and it works. (this is the code that checks the menu options)
Thanks for helping
|
|
|
|