Use Threading.Interlocked instead of direct assigned.
This commit is contained in:
MikeStall 2012-03-15 13:14:45 -07:00
Родитель a1eca4831b
Коммит cc10b42e05
2 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -6,6 +6,7 @@ using System.Net.Http.Formatting.Parsers;
using System.Net.Http.Internal;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
namespace System.Net.Http.Formatting
{
@ -101,7 +102,8 @@ namespace System.Net.Http.Formatting
{
// Initialize in a private collection to be thread-safe, and swap the finished object.
// Ok to double initialize this.
_nameValueCollection = HttpValueCollection.Build(this);
NameValueCollection newCollection = HttpValueCollection.Build(this);
Interlocked.Exchange(ref _nameValueCollection, newCollection);
}
return _nameValueCollection;
}

Просмотреть файл

@ -30,7 +30,7 @@ namespace System.Net.Http.Formatting
{
FormDataCollection form = new FormDataCollection(new Uri("http://foo.com"));
Assert.Equal(0, form.Count());
Assert.Empty(form);
}
[Fact]
@ -45,7 +45,7 @@ namespace System.Net.Http.Formatting
{
FormDataCollection form = new FormDataCollection("");
Assert.Equal(0, form.Count());
Assert.Empty(form);
}
[Fact]
@ -53,7 +53,7 @@ namespace System.Net.Http.Formatting
{
FormDataCollection form = new FormDataCollection((string) null);
Assert.Equal(0, form.Count());
Assert.Empty(form);
}
[Fact]