Re: Sleep Command for Window Methods?
- From: Matt Trivisonno <matt@xxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 20 Apr 2007 02:20:33 GMT
Joe Strout <joe@xxxxxxxxxx> wrote:
The term "entire main thread" suggests some misunderstanding. A thread
sleeps, or it doesn't sleep. It can't partially sleep.
Ok, but where in the docs is the "main thread" and its behavior spelled out?
How am I am supposed to know how these things work?
No, of course it's not impossible; you can have as many threads running
as you want, as I believe was already explained to you. If you stoutly
refuse to create threads for the different tasks you want to execute
simultaneously, then yes, of *course* they don't execute simultaneously.
I am creating threads. It is their interaction with my window methods that are
the problem.
if your processing takes longer than some reasonable value of
"immediately" then you should do it in a thread.
And that means that all database-update code must be done in threads (assuming
you want it to be bullet-proof) because sometimes the database will return a
"database is locked" error. Moving all database-update code to threads simply
strikes me as lacking in elegance.
Threads don't make spaghetti code; I use them whenever they're needed
and my code comes out neat. Yours can too. Just let go of this strange
desire you seem to have to want your code to behave like it's threaded,
without actually using threads. It's like saying, "I'm not willing to
put gas into my car, or switch to an electric car, but when I push the
gas pedal it doesn't go -- what's the deal?!?" Just put some friggin'
gas in it and get on with your app. :)
If I have to take two lines of code out of a window and move it into a thread,
I call that "spaghetti code". In object-oriented design, a window's code
ideally would reside within the window. If I want to execute this code:
db.SQLExecute("Some SQL Insert or Update")
db.Commit
...I cannot reliably do it in a window method. Sometimes the database will be
locked and the commit will fail. Putting the code into a loop and trying it
repeatedly until db.ErrorCode=0 will result in my app looking frozen. No
matter what device is used: sleeping the main thread, coding a tight loop,
using a semaphore, etc., the app will look frozen.
I want my windows to behave like independant objects, but I guess RB simply
does not work that way. I have been rasing this issue for a few months now,
and thought that I had a solution, but as far as I can tell the only real
solution is the hideously horrible approach of scattering my db-update code to
a swarm of threads.
Matt
Posted with NewzToolz. Free RAR, PAR, and yEnc decoders.
Get your free copy at www.techsono.com.
.
- Follow-Ups:
- Re: Sleep Command for Window Methods?
- From: Joe Strout
- Re: Sleep Command for Window Methods?
- Prev by Date: Re: Sleep Command for Window Methods?
- Next by Date: Re: Sleep Command for Window Methods?
- Previous by thread: Re: Sleep Command for Window Methods?
- Next by thread: Re: Sleep Command for Window Methods?
- Index(es):
Relevant Pages
|