Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions p4api.net/P4Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public partial class P4Server : IDisposable
{
public IKeepAlive KeepAlive { get; set; }

internal object Sync = new object();
internal readonly object Sync = new object();

private Dictionary<int, P4CommandResult> _lastResultsCache;
/// <summary>
Expand All @@ -93,20 +93,24 @@ public P4CommandResult LastResults
{
get
{
if (_lastResultsCache.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
lock (Sync)
{
return _lastResultsCache[System.Threading.Thread.CurrentThread.ManagedThreadId];
if (_lastResultsCache != null && _lastResultsCache.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
return _lastResultsCache[System.Threading.Thread.CurrentThread.ManagedThreadId];
}
return null;
}
return null;
}
internal set
{
if (_lastResultsCache == null)
{
_lastResultsCache = new Dictionary<int, P4CommandResult>();
}
lock (_lastResultsCache)
lock (Sync)
{
if (_lastResultsCache == null)
{
_lastResultsCache = new Dictionary<int, P4CommandResult>();
}

if (_lastResultsCache.Count > 32)
{
// if the results cache is getting large, throw away anything older than 10 seconds
Expand Down