I am working on a ASP.NET MVC app. I wanted to spawn few threads when a event occurs, I dont care for the return value of my threads and I wanted to make a async call so I am using ThreadPool.QueueUserWorkItem ,
public event SomeEventHandler SomeEvent;
private void SomeEventhappened(UserProfile arg)
{
SomeEventHandler handler = SomeEvent;
if (handler != null)
{
// handler(currentUser);
foreach (SomeEventHandler wc in handler.GetInvocationList())
{
SomeEventHandler wc2 = wc;
ThreadPool.QueueUserWorkItem(
delegate { wc2(arg); }
);
}
}
}
I have attached the event handler function to the event
This is how I raise the event,
this.SomeEventhappened(userProfile); //Here the event is raised
All the above code is happening in the same class. Only the event handler functions are in other class Do I need to kill my threads after they complete? Please suggest me if I am doing something wrong.