Why does this code not work if called within a new thread? The error returned is Object reference not set to an instance of an object. on the
return pb.GetPropertyValue("Name").ToString();
this works
GetFullName(m);
while this doesnt
Thread t = new Thread(GetFullName);
t.IsBackground = true;
t.Start();
public string GetFullName(string username)
{
ProfileBase pb = ProfileBase.Create(username);
return pb.GetPropertyValue("Name").ToString();
}
Maybe this is because the HttpContext.Current is not available in the new thread (which is to be expected).
I recommend that you extract the necessary data on your “main thread” (the one that is serving the request) and pass it manually to the new thread.
Edit: If you want to transfer the HttpContext, it works like this: