You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using miniprofiler in a non-mvc environment to capture sql timings
MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();
var cn = new ProfiledDbConnection(new OleDbConnection(config.IssuesDbConn), MiniProfiler.Current);
using Parallel.Invoke method to perform multiple methods against a group of databases (currently three different methods are running in parallel)
Occasionally receive a NRE in the GetCustomTimingList() method.
private List<CustomTiming> GetCustomTimingList(string category)
{
if (CustomTimings == null)
CustomTimings = new Dictionary<string, List<CustomTiming>>();
List<CustomTiming> result;
lock (CustomTimings)
{
if (!CustomTimings.TryGetValue(category, out result))
{
result = new List<CustomTiming>();
CustomTimings[category] = result;
}
}
return result;
I think what is happening is that there is a race condition between the time CustomTimings is checked for existence and the instant when it is created.
If I put a lock around the initial if statement, I haven't encountered the NRE (yet).
using miniprofiler in a non-mvc environment to capture sql timings
MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();
using Parallel.Invoke method to perform multiple methods against a group of databases (currently three different methods are running in parallel)
Occasionally receive a NRE in the GetCustomTimingList() method.
I think what is happening is that there is a race condition between the time CustomTimings is checked for existence and the instant when it is created.
If I put a lock around the initial if statement, I haven't encountered the NRE (yet).
Also, the code in this method may lose information in a concurrent environment. a decent explanation is at http://mortoray.com/2012/02/28/double-checked-locking-why-doesnt-it-work-and-how-to-fix-it/
The text was updated successfully, but these errors were encountered: