How can this program be adjusted so it won't take so
much cpu time:confused:
much cpu time:confused:
Try invoking Sleep in your ThreadProc.
invoke Sleep, <milliseconds to sleep>
invoke Sleep, <milliseconds to sleep>
listen to iblis.
And in general, don't do "delay factors" like that - use Sleep.
And in general, don't do "delay factors" like that - use Sleep.
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.
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.
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.
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.
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.
[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.
Hi iblis
The program just uses GetTickCount, to show how long
your pc has been turned on, that all.
Yeah, I see what you mean by that ;)
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:(
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:(
Hi The Shark,
Try eliminating the thread altogether and do the time stuff in your WM_TIMER handler.
Try eliminating the thread altogether and do the time stuff in your WM_TIMER handler.
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:
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:
Yeah I ran it ;)
It works fine. Nice job. :alright:
It works fine. Nice job. :alright: