How can this program be adjusted so it won't take so
much cpu time:confused:
Posted on 2003-04-18 03:33:50 by The SharK
Try invoking Sleep in your ThreadProc.

invoke Sleep, <milliseconds to sleep>
Posted on 2003-04-18 04:48:41 by iblis
listen to iblis.
And in general, don't do "delay factors" like that - use Sleep.
Posted on 2003-04-18 07:52:09 by f0dder
The easiest way would be to create a timer a time-out value of 1 second and update the window each time WM_TIMER is called.
Posted on 2003-04-18 08:05:18 by Delight
I have made a version to start with,
which uses a Timer, as Delight suggested,
but where is my thread now :confused:
When I use Taskinfo to check for it, it's gone :confused:



I have attached the new version.
Posted on 2003-04-18 17:45:08 by The SharK
I just glanced through your code so I'm not exactly sure what it's supposed to do, but I did notice a few things.

[size=12].IF ax==ButtonID_1

mov eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,eax,\
NULL,NORMAL_PRIORITY_CLASS,\
ADDR ThreadID
mov hThread,eax
invoke SetTimer, hWnd, EditControl_ID_1, 1000, addr ThreadProc

[...]

.ELSEIF uMsg==WM_TIMER
invoke UpdateWindow, hWnd
.ELSE[/size]



It looks like you're creating a thread and also creating a timer every time the button is pressed. I'm at a loss for words to describe my reaction to this but suffice it to say it's a bad thing to do. Generally you should not keep indescriminately creating handles without cleaning them up.

You also seem to have misunderstood delight's suggestion. The UpdateWindow() in your WM_TIMER handler is unnecessary because the SetDlgItemText() call in your ThreadProc will do the updating automatically.

I haven't actually run your program because I am afraid to do so ;) but if you want to tell us what it is your program is supposed to do then maybe we can help you better.
Posted on 2003-04-18 23:25:48 by iblis
Hi iblis

The program just uses GetTickCount, to show how long
your pc has been turned on, that all.


The UpdateWindow() in your WM_TIMER handler is unnecessary because the SetDlgItemText() call in your ThreadProc will do the updating automatically.

Yeah, I see what you mean by that ;)

Generally you should not keep indescriminately creating handles without cleaning them up.

Yep, I didn't thought of that:alright:

I seem to have trouble making the thread stuff work right,
or I've misunderstood the whole idea of using a thread:(
Posted on 2003-04-19 03:02:28 by The SharK
Hi The Shark,

Try eliminating the thread altogether and do the time stuff in your WM_TIMER handler.
Posted on 2003-04-19 11:03:03 by iblis
Hi iblis


I have removed the thread stuff, and put the time stuff
in the WM_TIMER handler.

Does the code seem clean now ?

Ps. I hope you aren't afraid anymore to run the program :tongue:
Posted on 2003-04-20 18:18:43 by The SharK
Yeah I ran it ;)

It works fine. Nice job. :alright:
Posted on 2003-04-20 20:07:16 by iblis