Restored from previous forum. Originally posted by Horst Hammer.
Hello,
I was looking arround in the posts for a while. But it seems as I am the first one with this kind of problem?
I want to make a client for a special networking application.
I packed everyting into procedures and i wanted to start 2 threads:
1 Thread that loops forever and fetches window_event
1 Thread for fetching the Network events (also looping)
If I normally call the Procedure with the window_event loop it works fine,
but if I try to start this Procedure as a Thread it immediatly exits the program and! the debugger? The Procedure is never called?
Or is there a better way to reduce CPU consumption than using threads?
Idea for a Multi-Thread App.?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Hi Horst, welcome to the PureBasic community.
For window events you don't need a own thread procedure to reduce cpu consumption.
Use WaitWindowEvent() in your Repeat/Until loop.
With the networking event, hmm... try to set a variable (inside the procedure as shared / outside the procedure as global).
Than you can change this variable in your thread-net-procedure (from 0 to 1 or whatever)if a network event occurs.
In your Repeat/Until loop you have to catch the changes of this variable and act.
This should work.
Don't forget - if you catch a network event - to set the variable back for the next network event.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 12 March 2002 16:10:02
Hi Horst, welcome to the PureBasic community.
For window events you don't need a own thread procedure to reduce cpu consumption.
Use WaitWindowEvent() in your Repeat/Until loop.
With the networking event, hmm... try to set a variable (inside the procedure as shared / outside the procedure as global).
Than you can change this variable in your thread-net-procedure (from 0 to 1 or whatever)if a network event occurs.
In your Repeat/Until loop you have to catch the changes of this variable and act.
This should work.
Don't forget - if you catch a network event - to set the variable back for the next network event.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 12 March 2002 16:10:02
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
A procedure as a thread is always running, if you use WaitWindowEvent() or WindowEvent() - otherwise it wouldn't be a thread.
The manual says:
WaitWindowEvent()
Wait until an event occurs. It's the same function than WindowEvent() but locks the program execution, which is very important in multitasking environment. An application should always use this command instead of WindowEvent()if possible. For more information, see the documentation of WindowEvent()
WindowEvent() eats up your cpu time - this is very bad for multithreading apps.
(You can put Delay(#) in your Repeat loop to prevent this...)
More useful is WaitWindowEvent() the CPU consumption is very small.
But how to get the variable value is described in the answer above.
Suppose you have to use a combination of WindowEvent() and Delay(#), otherwise you can't put:
If FetchNetworkEventVariable = 1
;do something
EndIf
in your Repeat loop, because WaitWindowEvent() locks your applications and no variable change is noticed.
Or you have to make a procedure (as thread) that simulates an window event when a variable changes his value or something like that.
Hope this helps.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 12 March 2002 22:26:41
NOPWouldn't WaitWindowEvent()stop the whole program?
A procedure as a thread is always running, if you use WaitWindowEvent() or WindowEvent() - otherwise it wouldn't be a thread.
The manual says:
WaitWindowEvent()
Wait until an event occurs. It's the same function than WindowEvent() but locks the program execution, which is very important in multitasking environment. An application should always use this command instead of WindowEvent()if possible. For more information, see the documentation of WindowEvent()
WindowEvent() eats up your cpu time - this is very bad for multithreading apps.
(You can put Delay(#) in your Repeat loop to prevent this...)
More useful is WaitWindowEvent() the CPU consumption is very small.
Sorry, I'm not working with network functions for now - so I'm not a big help in this.How can I fetch the network event then?
But how to get the variable value is described in the answer above.
Suppose you have to use a combination of WindowEvent() and Delay(#), otherwise you can't put:
If FetchNetworkEventVariable = 1
;do something
EndIf
in your Repeat loop, because WaitWindowEvent() locks your applications and no variable change is noticed.
Or you have to make a procedure (as thread) that simulates an window event when a variable changes his value or something like that.
Hope this helps.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Edited by - franco on 12 March 2002 22:26:41
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tranquil.
Hi Horst!
Your name listens like a german guy.
I'm german too and my mainly aim is to code Network-Applications in PB. Possible we can help us together.
Just contact me at my email [url]mailto:tranquil@gmx.net[/url] or in the (german) purebasic chat.
I'm also intrested in your network experiences with PB and your work.
Bye
Tranquilizer/ Secretly!
Registred PureBasic User
Hi Horst!
Your name listens like a german guy.
Just contact me at my email [url]mailto:tranquil@gmx.net[/url] or in the (german) purebasic chat.
I'm also intrested in your network experiences with PB and your work.
Bye
Tranquilizer/ Secretly!
Registred PureBasic User