472,364 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

How can I check for thread existense ?

I am using VB.NET 2005. To check if the same program already run or not, I
can use the following

If Process.GetProcessesByName(Process.GetCurrentProce ss.ProcessName).Length
1 Then
MsgBox("Another instance of " & Process.GetCurrentProcess.ProcessName &
" is already running !")
End
End If

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.
Aug 27 '07 #1
9 4004
"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...

Aug 27 '07 #2
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...

Aug 27 '07 #3
Thank you.
What is semaphore type ?
"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...


Aug 28 '07 #4
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...


Aug 28 '07 #5
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...



Aug 28 '07 #6
Thank you.
But, I have 2 different thread running on the application, and I would like
to allow those 2 threads only. They both have a different name, say
"ThreadA" and "ThreadB"
I only want 1 instance of "ThreadA" and 1 instance of "ThreadB"
Can I use semaphore to do that ?
"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
>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...



Aug 29 '07 #7
"fniles" <fn****@pfmail.comwrote in
news:eq**************@TK2MSFTNGP02.phx.gbl:
But, I have 2 different thread running on the application, and I would
like to allow those 2 threads only. They both have a different name,
say "ThreadA" and "ThreadB"
I only want 1 instance of "ThreadA" and 1 instance of "ThreadB"
Can you check the valud of the Thread Variable?

If ThreadA is Nothing then
'Do stuff here to initialize thread
Else
msgbox("Thread already created")
End if
Aug 29 '07 #8
Yes, I can do that. Thank you.
I was thinking to check for it inside the thread itself.
Can I do that ?

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"fniles" <fn****@pfmail.comwrote in
news:eq**************@TK2MSFTNGP02.phx.gbl:
>But, I have 2 different thread running on the application, and I would
like to allow those 2 threads only. They both have a different name,
say "ThreadA" and "ThreadB"
I only want 1 instance of "ThreadA" and 1 instance of "ThreadB"

Can you check the valud of the Thread Variable?

If ThreadA is Nothing then
'Do stuff here to initialize thread
Else
msgbox("Thread already created")
End if

Aug 30 '07 #9

Yes you can do that by using 2 semaphores
"fniles" <fn****@pfmail.comschreef in bericht
news:eq**************@TK2MSFTNGP02.phx.gbl...
Thank you.
But, I have 2 different thread running on the application, and I would
like to allow those 2 threads only. They both have a different name, say
"ThreadA" and "ThreadB"
I only want 1 instance of "ThreadA" and 1 instance of "ThreadB"
Can I use semaphore to do that ?
"Michel Posseth [MCP]" <MS**@posseth.comwrote in message
news:eV**************@TK2MSFTNGP05.phx.gbl...
>>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...
>




Aug 31 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sameh Ahmed | last post by:
Hello there Is there a way through dotNet to check if a certain user is a member of a specific group? I use ADSI to get the memberships of the user then compare them to the group I want to check,...
6
by: Hermann Maier | last post by:
Hi, i am using the com api of a program and if this program is shut down and my program calls a method of the api, it crashs. that means, i need to check, if the com server is still available,...
0
by: Hermann Maier | last post by:
Hi, i am using the com api of a program and if this program is shut down and my program calls a method of the api, it crashs. that means, i need to check, if the com server is still available,...
5
by: ags5406 | last post by:
I've a Windows Service that keeps a particular executable running. If the executable fails for whatever reason, the Service restarts it. Right now I'm using a loop to check if the process is...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.