Solved

Finding the original thread in a Class Library

Posted on 2006-11-14
3
186 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now