473,698 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetProc essesByName(Pro cess.GetCurrent Process.Process Name).Length
1 Then
MsgBox("Another instance of " & Process.GetCurr entProcess.Proc essName &
" 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 4138
"fniles" <fn****@pfmail. comwrote in
news:#N******** *****@TK2MSFTNG P05.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**********@r ogers.comschree f in bericht
news:Xn******** *************** ***********@127 .0.0.1...
"fniles" <fn****@pfmail. comwrote in
news:#N******** *****@TK2MSFTNG P05.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.c omwrote in message
news:u6******** ******@TK2MSFTN GP02.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**********@r ogers.comschree f in bericht
news:Xn******** *************** ***********@127 .0.0.1...
>"fniles" <fn****@pfmail. comwrote in
news:#N******* ******@TK2MSFTN GP05.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.c omwrote in message
news:u6******** ******@TK2MSFTN GP02.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**********@r ogers.comschree f in bericht
news:Xn******** *************** ***********@127 .0.0.1...
>"fniles" <fn****@pfmail. comwrote in
news:#N******* ******@TK2MSFTN GP05.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******** ******@TK2MSFTN GP06.phx.gbl...
And how can I use the semaphore type to detect multiple instances of the
same thread ?

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:u6******** ******@TK2MSFTN GP02.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**********@r ogers.comschree f in bericht
news:Xn******* *************** ************@12 7.0.0.1...
>>"fniles" <fn****@pfmail. comwrote in
news:#N****** *******@TK2MSFT NGP05.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.c omwrote in message
news:eV******** ******@TK2MSFTN GP05.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******** ******@TK2MSFTN GP06.phx.gbl...
>And how can I use the semaphore type to detect multiple instances of the
same thread ?

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:u6******* *******@TK2MSFT NGP02.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**********@r ogers.comschree f in bericht
news:Xn****** *************** *************@1 27.0.0.1...
"fniles" <fn****@pfmail. comwrote in
news:#N***** ********@TK2MSF TNGP05.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******** ******@TK2MSFTN GP02.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**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"fniles" <fn****@pfmail. comwrote in
news:eq******** ******@TK2MSFTN GP02.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******** ******@TK2MSFTN GP02.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.c omwrote in message
news:eV******** ******@TK2MSFTN GP05.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
maximumcount s are ignored
HTH

Michel

"fniles" <fn****@pfmail. comschreef in bericht
news:e3******* *******@TK2MSFT NGP06.phx.gbl.. .
>>And how can I use the semaphore type to detect multiple instances of the
same thread ?

"Michel Posseth [MCP]" <MS**@posseth.c omwrote in message
news:u6****** ********@TK2MSF TNGP02.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**********@r ogers.comschree f in bericht
news:Xn***** *************** **************@ 127.0.0.1...
"fniles" <fn****@pfmail. comwrote in
news:#N**** *********@TK2MS FTNGP05.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
3762
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, but this way the user has to be a member of this group directly and if he is a member of a group that is a member of that group he will not be considered a member of the group I am checking although he is implicitly. so basically what I need is...
6
1610
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, before i can call for it. i already have a solution for this problem and it works quiet well, but i think, it is not that nice. my solution works that way, that i create a new thread, call a method of my com object and write back a value in my...
0
284
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, before i can call for it. i already have a solution for this problem and it works quiet well, but i think, it is not that nice. my solution works that way, that i create a new thread, call a method of my com object and write back a value in my...
5
1815
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 running. I started with an infinite loop that ate up all of my resources, but then added a 2 second pause after every check, which seems to have mostly eliminated the problem of my resources being used up. However, I'm wondering if there is a...
0
8671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9152
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9016
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8856
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.