473,695 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Thread.Join()

Hi All

I am just double checking myself here.

I have two threads that i am running in an application, One Thread Updates a
client side Table in a local DB, another Updates a Server Side Table on a
Server DB (I know i dont like it either but for some reason they want two
seperate DB's, go figure!!)
Anyway, I use the following code to Kick off the Threads:
'While the thread state is running, loop until it is
stopped
While intRunningState <> connThread.Thre adState.Stopped
Or intRunningState 2 <> connUpldThread. ThreadState.Sto pped

If Not blnIsRunning Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Re trieving Records, Please Wait....</FONT>", True)
blnIsRunning = True
connThread.Star t()
intRunningState = connThread.Thre adState
connThread.Join ()
connUpldThread. Start()
connUpldThread. Join()
intRunningState 2 = connUpldThread. ThreadState

End If
intRunningState = connThread.Thre adState
intRunningState 2 = connUpldThread. ThreadState
If connUpldThread. ThreadState = 0 Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Se nding Records, Please Wait....</FONT>", True)
End If
End While

What i want to know is, am i using the Join statement Correctly? I do want
one Thread to finish before the other starts in an effort to co-ordinate
this process. Please let me know

Thanks in advance

Samantha
Nov 18 '05 #1
2 2196
The join is correct for what you are attempting to do.

I've taken the liberty of glancing over your code.
'While the thread state is running, loop until it is stopped logic error here. what if your thread can't talk to the database, thru
connectivity issues, OR the thread aborts or is suspended. What if the
thread fails to stop or you cannot read the thread state? Your application
enters an infinite loop. The loop is tight enough to bring down the server.
You should OR the different thread states together to test for the other
cases like aborted | suspended | stopped etc. instead of just testing for
stopped state

There is still another issue. You aren't protecting your code against a long
running thread. What if your thread decides to run for 5 hours? You have no
safeguard in the code for that. For this you may want to force an abort
after an unnecessarily long period of time.

--
Regards,
Alvin Bruney
Got Tidbits? Get it here
www.networkip.net/tidbits
"Elizabeth Harmon" <EH*****@bloomi ngtonfarms.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl... Hi All

I am just double checking myself here.

I have two threads that i am running in an application, One Thread Updates a client side Table in a local DB, another Updates a Server Side Table on a
Server DB (I know i dont like it either but for some reason they want two
seperate DB's, go figure!!)
Anyway, I use the following code to Kick off the Threads:
'While the thread state is running, loop until it is
stopped
While intRunningState <> connThread.Thre adState.Stopped Or intRunningState 2 <> connUpldThread. ThreadState.Sto pped

If Not blnIsRunning Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Re trieving Records, Please Wait....</FONT>", True)
blnIsRunning = True
connThread.Star t()
intRunningState = connThread.Thre adState
connThread.Join ()
connUpldThread. Start()
connUpldThread. Join()
intRunningState 2 = connUpldThread. ThreadState

End If
intRunningState = connThread.Thre adState
intRunningState 2 = connUpldThread. ThreadState
If connUpldThread. ThreadState = 0 Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Se nding Records, Please Wait....</FONT>", True)
End If
End While

What i want to know is, am i using the Join statement Correctly? I do want
one Thread to finish before the other starts in an effort to co-ordinate
this process. Please let me know

Thanks in advance

Samantha

Nov 18 '05 #2
Thanks for the Advice, i will go with a select statement in the loop so i
can test for those conditions
Samantha
"Alvin Bruney" <va******@hotsp ammailme.com> wrote in message
news:ud******** ******@TK2MSFTN GP10.phx.gbl...
The join is correct for what you are attempting to do.

I've taken the liberty of glancing over your code.
'While the thread state is running, loop until it is stopped logic error here. what if your thread can't talk to the database, thru
connectivity issues, OR the thread aborts or is suspended. What if the
thread fails to stop or you cannot read the thread state? Your application
enters an infinite loop. The loop is tight enough to bring down the

server. You should OR the different thread states together to test for the other
cases like aborted | suspended | stopped etc. instead of just testing for
stopped state

There is still another issue. You aren't protecting your code against a long running thread. What if your thread decides to run for 5 hours? You have no safeguard in the code for that. For this you may want to force an abort
after an unnecessarily long period of time.

--
Regards,
Alvin Bruney
Got Tidbits? Get it here
www.networkip.net/tidbits
"Elizabeth Harmon" <EH*****@bloomi ngtonfarms.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
Hi All

I am just double checking myself here.

I have two threads that i am running in an application, One Thread Updates
a
client side Table in a local DB, another Updates a Server Side Table on

a Server DB (I know i dont like it either but for some reason they want two seperate DB's, go figure!!)
Anyway, I use the following code to Kick off the Threads:
'While the thread state is running, loop until it is
stopped
While intRunningState <>

connThread.Thre adState.Stopped
Or intRunningState 2 <> connUpldThread. ThreadState.Sto pped

If Not blnIsRunning Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Re trieving Records, Please Wait....</FONT>", True)
blnIsRunning = True
connThread.Star t()
intRunningState = connThread.Thre adState
connThread.Join ()
connUpldThread. Start()
connUpldThread. Join()
intRunningState 2 = connUpldThread. ThreadState
End If
intRunningState = connThread.Thre adState
intRunningState 2 = connUpldThread. ThreadState
If connUpldThread. ThreadState = 0 Then
'Writer Updates the Screen for the User
WriteStatusUpda te(writer, "<BR><FONT
color='blue'>Se nding Records, Please Wait....</FONT>", True)
End If
End While

What i want to know is, am i using the Join statement Correctly? I do want one Thread to finish before the other starts in an effort to co-ordinate
this process. Please let me know

Thanks in advance

Samantha


Nov 18 '05 #3

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

Similar topics

3
3233
by: Peter Hansen | last post by:
I'm still trying to understand the behaviour that I'm seeing but I'm already pretty sure that it's either a bug, or something that would be considered a bug if it didn't perhaps avoid even worse behaviour. Inside the join() method of threading.Thread objects, a Condition named self.__block is acquired, and then the wait logic is executed. After the wait() finishes, self.__block is released and the method returns.
13
2061
by: Paul | last post by:
Hi, How do I wait until a thread is finished his job then continue to the original thread? public void main(string args) { Thread t = new Thread(new ThreadStart(DoWork)); t.Start();
4
1164
by: denton | last post by:
I want to read a line from the textbox just like a console window. The called thread will not allow me to enter keys when I call Join. I have stuck on this problem for 2 weeks: private void button3_Click(object sender, EventArgs e) { ReadLine(); } public string ReadLine() { Thread w1 = new Thread(new ThreadStart(ReadLineFunct));
1
1269
by: Elizabeth Harmon | last post by:
hi all, Just when you think you understand and are getting all this, .Net throws you a Curve I have the following Code Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) Dim connThread As Thread = New Thread(New ThreadStart(AddressOf
6
1916
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create a new thread to display a customer on the screen for example. However, I have a problem with circular references in my objects which means that I have to load the customer object using reflection ie :
14
37373
by: Joe | last post by:
Does anyone know the difference, in practical terms, between Thread.Sleep (10000) and Thread.CurrentThread.Join (10000)?? The MSDN says that with Join, standard COM and SendMessage pumping continues, but what does this mean in practice for a typical Windows Forms or Windows Service application?? Some people say you should always use the latter.
6
5811
by: Extremest | last post by:
I am new to threading and trying to figure some things out. Are all variables in a thread set to only that thread? Meaning if I create 2 instances of a class and then put each one in a different thread and run them will the local variables in functions be shared or will they be thread safe?
5
3799
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the mysql connections open so I end up with quite a few at the end. Is there a different way that I should do this? class Program { static string categories = { "emulation" , "audio" , "console" , "anime" , "xxx" , "tv" , "pictures" , "video" };
1
3303
by: Chrace | last post by:
Hi all, I have a problem with with Thread.Join( Timeout ) where the timeout never occurs. I basically need to make a connection to an AS400 box which works fine. Once in a blue moon the AS400 gets a problem and the way this is handled on AS400 is by hanging. If I was to connect directly this would mean my main process would hang as well, so I've spawned a worker thread and used a Thread.Join( Timeout ) to make sure it always returns with...
0
8638
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
9120
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
8998
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
8831
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...
1
6494
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
4584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3013
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2278
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1979
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.