Solved

Finding the original thread in a Class Library

Posted on 2006-11-14
3
189 Views
Last Modified: 2010-04-16
I've created a class library which creates a seperate thread to do some of the work, how do i refer back to the original thread once its finished? In a winform i'd use invoke however it doesn't seem to exist in the class.
0
Comment
Question by:James_Wyatt
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17939094
You can raise event from this thread immediately before thread exits. In the caller class subscribe to this event. When event is raised, thread is "almost" finished. Notice that event handler is called in the context of worker thread.
0
 
LVL 12

Accepted Solution

by:
andrewjb earned 125 total points
ID: 17945681
....and thus doesn't solve the problem.


There's no 'built-in' way to cross thread boundaries, other than crossing into the GUI thread using Invoke(). You have to implement something yourself.

The simplest way would be something like a common variable that the worker thread sets and the original thread regularly polls to look for changes. (Don't forget a suitable lock() of course).

Alternatively you could use a mutex or semaphore or similar mechanism, or implement an equivalent to the Invoke() mechanism which would work on non-GUI threads.

I've ended up doing the latter since it's a complex multi-thread system, but hopefully a simpler option will do you..
0
 
LVL 1

Author Comment

by:James_Wyatt
ID: 17997100
Thanks for your help. In the end i used a passed a form to the dll so the it could use invoke().
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question