473,789 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stop Thread until specified action in another thread

I have MS Word operating in a thread other than the main writing a report.
Can I tell the main thread to wait until a particular point (a sub starts)
in another thread before continuing on?
Nov 20 '05 #1
1 1554
You can use an AutoResetEvent. When you create it the param is True or
False. If it is False then when you do WaitOne it waits. If you create it
with a True param you need to .Reset before you .WaitOne

Imports System.Threadin g

Public Class Form1
Inherits System.Windows. Forms.Form

Private Shared autoReset As New AutoResetEvent( False)

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

Thread.CurrentT hread.Name = "GUI Thread"

Debug.WriteLine (Thread.Current Thread.Name & " started")

Dim workerThread As Thread = New Thread(AddressO f DoSomething)

workerThread.Na me = "Worker thread"
workerThread.St art()

Debug.WriteLine (Thread.Current Thread.Name & " about to wait")

autoReset.WaitO ne()

Debug.WriteLine (Thread.Current Thread.Name & " finishing")

End Sub

Private Sub DoSomething()
Dim i As Integer

Debug.WriteLine (Thread.Current Thread.Name & " DoSomething")

For i = 1 To 5
Debug.WriteLine (Thread.Current Thread.Name & " sleeping...")
Thread.CurrentT hread.Sleep(500 )
Next
Debug.WriteLine (Thread.Current Thread.Name & " exit DoSomething")
autoReset.Set()
End Sub
End Class

"scorpion53 061" <Its the end of the world as we know it@here.com> wrote in
message news:um******** ******@TK2MSFTN GP10.phx.gbl...
I have MS Word operating in a thread other than the main writing a report.
Can I tell the main thread to wait until a particular point (a sub starts)
in another thread before continuing on?

Nov 20 '05 #2

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

Similar topics

15
1597
by: Valkyrie | last post by:
Refering to the following codes I found, there is nothing displayed in the console, may I ask why? def thrd(param): # the thread worker function print "Received",param import thread for i in range(5): # start five threads passing i to each one thread.start_new_thread(thrd,(i,))
6
11665
by: Baffin Shea | last post by:
Dear All, I am a beginner in javascript and looking for help, I put the following script in the original.asp: function NewWindows() { window.open("abc.asp", "new") }
2
5294
by: 0to60 | last post by:
I have a windows service that when started creates two threads: one thread that runs a TcpListener waiting for TcpClients to connect, and another thread that reads from the resulting sockets. My stop code .Abort()s the threads and .Stop()s the listener. One one of my computers, the service runs like, well...a service. It starts and stops nicely. On a different computer (eventually this service will be running on 50+ machines) the...
8
2313
by: Tim Bücker | last post by:
Following scenario: The user opens a form, a thread is started to play a sound ... public void playSoundUsingThread() { if (File.Exists(fileLocation)) PlaySound(fileLocation, 0, 0); // winmm.dll }
26
4704
by: Ricardo | last post by:
I made a program that generate random numbers and put it in a listbox when the user click go. The problem is: how can i made a button stop, to stop the method that is running??? s...
51
54881
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() # This thread is expected to finish within a second
5
6456
by: many_years_after | last post by:
Hi, pythoners: There is a problem I couldn't dispose. I start a thread in the my program. The thread will do something before executing time.sleep(). When the user give a signal to the main thread (such as click the 'end' button or close the window), the thread should end it's running. But how to end the threading when it's sleeping? I set an flag to the thread, but it doesn't work. I also thought to put 'time.sleep()' to the main...
8
2051
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for button A's mouseup has completed? I beleive event processing to be single-threaded for good reason but I need a "stop" button and it's no good if it doesn't do anything until the other processing has finished :-)
7
7692
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort() on the request object on another thread, GetResponse() returns with an exception as expected. However, when I monitor the network traffic, it does not seem to stop, but to continue to be active and to upload the file. The network is active even...
0
9665
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
9511
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
10408
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...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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
7529
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
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.