Hi to all,
well i've a little question about thread behaviour under vb
If i call a sync function from my vb program thread that thread becomes blocked untill the function returns
But in the meanwhile my vb program is still able to handle messages coming from the gui such as button pressing and so on
That means theres another thread in my vb app but from that thread i can issue only async operations otherwise i'll block that thread too and my app is freezed is it right ?
Well i've done some experiments and that seems to be the behvaiour of the vb app
My questions is this one:
if i block the program thread calling a sync method that blocks the thread with a WaitForSignleObject() and i unblock that thread pressing another button on the form (that means theres another thread in my vb app thats not blocked) that calls SetEvent()
is it dangerous or wrong as way of working ?

Tnx a lot
NikDH
Posted on 2002-03-01 10:09:18 by NikDH
I know really little about vb but imho this is a pretty normal case of thread syncronization. I don't think there's anything dangerous with this: just two threads blocking and unblocking each other.
Posted on 2002-03-01 14:51:03 by acab
Heh, i thought i would stray a little from my usual patch, and look where i popped up.....

If i call a sync function from my vb program thread that thread becomes blocked untill the function returns
Correct, this is the case for most API calls, and quite a few calls through database drivers, etc.


But in the meanwhile my vb program is still able to handle messages coming from the gui such as button pressing and so on
Wrong. Unless you have done something totally different, a VB app remains blocked during a blocking call. If your VB app is redrawing itself, or generally responding, then you are not in a blocking call. To illustrate this, try sending a complex sql statement to a database, or do a wininet call that takes a while to complete, you will see that your app does not respond, and indeed will not even get repainted by Windows while the blocking call is in progress.


That means theres another thread in my vb app
From the program and the programmers perspective, VB is a single-threaded enviroment.


but from that thread i can issue only async operations otherwise i'll block that thread too and my app is freezed is it right ?
Think of it this way: did you specifically code that separate thread? If not, you cannot "issue" anything from it, the only thing you can do is send it messages and/or communicate with it via a mechanism it has exposed. This goes for threads in any language.


Well i've done some experiments and that seems to be the behvaiour of the vb app
I would like to see those experiments, you have done something wrong :)

if i block the program thread calling a sync method that blocks the thread with a WaitForSignleObject() and i unblock that thread pressing another button on the form
Another thread cannot just "unblock" a thread that is waiting for an object to become signalled. The only way to do what you just proposed is to satisfy the Wait object (or for it to time out), and the only way (that i know of) to satisfy that Wait object is for the Wait object to be governing the thread that is trying to do the unblocking........

I hope i haven't been too confusing with my explanations.....
Posted on 2002-03-26 06:20:18 by sluggy