473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Thead Completion

How can I determine the moment a thread finishes?

I start the thread this way:

Dim x As New Threading.Thread(AddressOf (MySub))

x.Start

Is there any x.Finished type of Event or how can do this?

Thanks


Nov 21 '05 #1
3 1264

There is no built-in event.

You can have MySub raise a custom event or you can use a custom thread
class that adds this event. The only kink here is that Thread is
declared as NotInheritable so you have to proxy all of the
properties/methods from your custom class to the base Thread instance
and the containing variable must be declared as your custom type and
not Thread. Would have been much simpler if Thread was not declared
NotInheritable and if Start was overridable.

HTH,

Sam
Incomplete example (only proxies the Start method):
Imports System.Threading

Public Class ConsiderateThread
Private _underlyingThread As Thread
Private _underlyingStart As ThreadStart

Public Event ThreadCompleted As EventHandler

Public Sub New(ByVal start As ThreadStart)
_underlyingStart = start
_underlyingThread = New Thread(AddressOf ConsiderateStart)
End Sub

Public Sub Start()
_underlyingThread.Start()
End Sub

Private Sub ConsiderateStart()
_underlyingStart.Invoke()
RaiseEvent ThreadCompleted(Me, EventArgs.Empty)
End Sub
End Class

Public Class ConsiderateThreadTester
Public Shared Sub Test()
Dim t As New ConsiderateThread(AddressOf DoSomething)
AddHandler t.ThreadCompleted, AddressOf DoSomethingDone
t.Start()
Thread.Sleep(5000)
Console.WriteLine("Test Done")
End Sub
Public Shared Sub DoSomethingDone(ByVal sender As Object, ByVal e
As EventArgs)
Console.WriteLine("DoSomethingDone")
End Sub
Public Shared Sub DoSomething()
Console.WriteLine("DoSomething")
End Sub
End Class


On Fri, 21 Jan 2005 12:48:33 -0600, "TCORDON" <tc******@hotmail.com>
wrote:
How can I determine the moment a thread finishes?

I start the thread this way:

Dim x As New Threading.Thread(AddressOf (MySub))

x.Start

Is there any x.Finished type of Event or how can do this?

Thanks


Nov 21 '05 #2
It's a little tricky, but you can use an asynchronous deleagate instead of
the thread class. With a delegate, you start a thread in the background, and
specify a callback method that will be invoked as soon as the thread
completes.

Look here for a start
http://msdn.microsoft.com/library/de...rnoverview.asp

Scott Swigart
www.swigartconsulting.com
blog.swigartconsulting.com
"TCORDON" wrote:
How can I determine the moment a thread finishes?

I start the thread this way:

Dim x As New Threading.Thread(AddressOf (MySub))

x.Start

Is there any x.Finished type of Event or how can do this?

Thanks


Nov 21 '05 #3
"TCORDON" <tc******@hotmail.com> schrieb:
How can I determine the moment a thread finishes?


You can do that using 'IAsyncResult'. A sample can be found here:

FileSystemEnumerator
<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/FileSystemEnumerator.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

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

Similar topics

3
by: John | last post by:
Hi, Could you give your opinions on the best code completion in Python IDEs. My only complaint with PythonWin has been that the code completion support is incomplete. The interactive mode has...
11
by: Woolly Mittens | last post by:
I tried validating my gallery page using your validator. http://validator.w3.org/check?uri=http%3A%2F%2Fwww.woollymittens.nl%2Fcontent%2Fgallery%2Findex.asp To my surprise it informed me that...
0
by: Nadav | last post by:
Hi, Usage of FileStream ( and other stream related objects ) internally use an IO Completion port, Now, Taking that in mind, does all of the stream object of a certain process use a single IO...
0
by: Hiroyuki Tanaka | last post by:
Hi, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to my...
0
by: Hiroyuki Tanaka | last post by:
Hi All, I am trying to develop an application for a touch screen using buttons for the numeric pad with Completion ComboBoxes. At the moment I am having a problem sending the button presses to...
1
by: David L | last post by:
Is anyone aware of a method to get the datagrid control to spit out <thead> and <th> tags for headers? I really want to avoid some pre-render hack manipulating strings in the output stream. ...
0
by: Oded | last post by:
Hi, I'm working on an ASP.NET application, written in C#, using VS.NET . When working on aspx pages, HTML completion does not work (neither tag closing nor statement completion). Completion works...
4
by: Rob Richardson | last post by:
Greetings! I am trying to write a set of macros to generate Property code for private variables. With the cursor on a line that says "Private m_MyThing as Thing", I would run the macro and ...
0
by: redaudi | last post by:
I'm hoping someone might be able to help me with the following issue. Basically I'm creating a htmltable on the fly and then simply populating it with rows and cells accordingly. My test site ...
0
by: makifsar | last post by:
I am using a comserver to communicate remote equipments. This server gives response via WndProc. First I call READ function to start communication and remote equipment gives response this via...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.