0

I've got a weird issue going on. I'm calling the profile for another user (not the currently authenticated user) and trying to access a value.

 var profile = System.Web.Profile.ProfileBase.Create(username, true);
 if (profile.PropertyValues["x"] != null)
     ddlList.SelectedValue = profile.PropertyValues["x"].PropertyValue.ToString();

The value 'x' does exist for the user, but it's returning null. If I step through the code, and actually view the profile values before the if statement, then it works as expected. So I have to explicitly step through the code and view the value for the app to actually acknowledge it.

atfergs
  • 1,674
  • 1
  • 11
  • 17
  • To me, that sounds like a classic race condition. Put a `Thread.Sleep(5000);` between getting the profile and the if. If it then runs correctly, then it is a race condition after all. _BUT PLEASE, REMOVE THE SLEEP THEN, AND COME UP WITH A BETTER SOLUTION!_ Delays can help you identify a race condition, they are NOT a solution for it. – Jan Dörrenhaus May 24 '13 at 00:14
  • Nope, didn't help. Good idea, though. – atfergs May 24 '13 at 00:19
  • Then I am stumped. Your code appears to be correct. Maybe someone else will be able to help you, though. – Jan Dörrenhaus May 24 '13 at 00:27

0 Answers0