Solved

Finding the original thread in a Class Library

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 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

17 Experts available now in Live!

Get 1:1 Help Now