Try to search your question here, if you can't find : Ask Any Question Now ?

How can I shared a execution context between a group of threads?

HomeCategory: stackoverflowHow can I shared a execution context between a group of threads?
Avatarpushpa asked 4 months ago

In Foo method, I create some task and I want to set a context in the main thread and access to it from other threads, is there any way I shared a context between my main thread and other threads than created in the main thread? I don’t want to pass context to other threads and my preference is to set the context in a single point like in a custom lifestyle in IOC container for my execution context

public class IUserContext
{
    string UserName {get;}
    string Token {get;}
}

public void Foo()
{//I set the context data before calling the method
    foreach(...) {
        Task.Factory.StartNew(() =>method1);
    }

    void method1()
    {
         // context is null
         var context = Container.Resolve<IUserContext>();
    }
}
1 Answers
Best Answer
AvatarArben answered 4 months ago
Your Answer

1 + 5 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com