Solved

Finding the original thread in a Class Library

Posted on 2006-11-14
3
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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