a thread can attempt to take ownership of the semaphore by calling the
waitone method , if the current count is higher as zero ( count of the
number of threads you allow ) , the semaphore returns inmediatly ,
otherwise it will wait until anoher thread releases the semaphore , or until
the optional timeout expires
here is an MSDN example
http://msdn2.microsoft.com/en-us/lib...semaphore.aspx
P.s.
remember to use a try finally block to ensure thet the semaphore is released
even if the code throws an exception
Like mutexes semaphores can have a name and be shared among processes when
you try to create a sempahore that already exists the initial and
maximumcounts are ignored
HTH
Michel
"fniles" <fn****@pfmail.comschreef in bericht
news:e3**************@TK2MSFTNGP06.phx.gbl...
And how can I use the semaphore type to detect multiple instances of the
same thread ?
"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:u6**************@TK2MSFTNGP02.phx.gbl...
>Mutexes are normally used for detecting multiple instances of the same
app
For threading you normally use the semaphore type
regards
michel
"Spam Catcher" <sp**********@rogers.comschreef in bericht
news:Xn**********************************@127.0.0 .1...
>>"fniles" <fn****@pfmail.comwrote in
news:#N*************@TK2MSFTNGP05.phx.gbl:
I am wondering if I can check the same thing for a thread.
I have 1 thread that I do not want to create multiple instances of.
Can I check whether the thread has exists before or not ?
Thank you.
You would use a System Mutex to check if an instance is running. There
should be an example on google (used to be plenty, but I can't seem to
find
one!!!)
But VB.NET 2005 already has an option to limit the application to one
instance...