views:

66

answers:

1
+1  Q: 

Get calling thread

Is there a way to get the information of the main thread (the application thread) from a second thread?

My problem is that I have to set the currentprincipal in the main thread, but the authentication is done in another thread because it's a long and complex task, but when I set the currentPrincipal in the second thread, the main thread does not have the information.

Thanks for any help.

+3  A: 

Create a static variable on the module that both threads will execute inside of. Set the variable in the main thread and access it in the 2nd.

kmehta
Or pass it along in some state object.
Henk Holterman
or have the second thread call back using a delegate or event.
Will
@Will, wouldn't the execution of that delegate or event occur on the second thread? (unless you used Invoke())
Robert H.
@Robert, you are correct, I was implying instead of the static variable you could use a class variable, and then have the second thread set the variable to be used by the first thread (using the callback delegate). Using this approach the authentication piece would be more in closed and not reliant on a shared static variable.
Will