本文整理汇总了C#中ThreadLocal.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ThreadLocal.ToString方法的具体用法?C# ThreadLocal.ToString怎么用?C# ThreadLocal.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ThreadLocal
的用法示例。
在下文中一共展示了ThreadLocal.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunThreadLocalTest2_ToString
public static void RunThreadLocalTest2_ToString()
{
ThreadLocal<object> tlocal = new ThreadLocal<object>(() => (object)1);
if (tlocal.ToString() != 1.ToString())
{
Assert.True(false,
string.Format("RunThreadLocalTest2_ToString: > test failed - Unexpected return value from ToString(); Actual={0}, Expected={1}.",
tlocal.ToString(), 1.ToString()));
}
}
示例2: RunThreadLocalTest2_ToString
/// <summary>Tests for the ToString.</summary>
/// <returns>True if the tests succeeds, false otherwise.</returns>
private static bool RunThreadLocalTest2_ToString()
{
TestHarness.TestLog("* RunThreadLocalTest2_ToString()");
ThreadLocal<object> tlocal = new ThreadLocal<object>(() => (object)1);
if (tlocal.ToString() != 1.ToString())
{
TestHarness.TestLog(" > test failed - Unexpected return value from ToString(); Actual={0}, Expected={1}.", tlocal.ToString(), 1.ToString());
return false;
}
return true;
}
示例3: RunThreadLocalTest5_Dispose
private static bool RunThreadLocalTest5_Dispose()
{
TestHarness.TestLog("* RunThreadLocalTest5_Dispose()");
ThreadLocal<string> tl = new ThreadLocal<string>(() => "dispose test");
string value = tl.Value;
tl.Dispose();
if (!TestHarnessAssert.EnsureExceptionThrown(() => { string tmp = tl.Value; }, typeof(ObjectDisposedException), "The Value property of the disposed ThreadLocal object should throw ODE"))
return false;
if (!TestHarnessAssert.EnsureExceptionThrown(() => { bool tmp = tl.IsValueCreated; }, typeof(ObjectDisposedException), "The IsValueCreated property of the disposed ThreadLocal object should throw ODE"))
return false;
if (!TestHarnessAssert.EnsureExceptionThrown(() => { string tmp = tl.ToString(); }, typeof(ObjectDisposedException), "The ToString method of the disposed ThreadLocal object should throw ODE"))
return false;
// test recycling the combination index;
tl = new ThreadLocal<string>(() => null);
if(tl.IsValueCreated)
{
TestHarness.TestLog("* Filed, reusing the same index kept the old value and didn't use the new value.");
return false;
}
if (tl.Value != null)
{
TestHarness.TestLog("* Filed, reusing the same index kept the old value and didn't use the new value.");
return false;
}
return true;
}
示例4: RunThreadLocalTest2_ToString
public static void RunThreadLocalTest2_ToString()
{
ThreadLocal<object> tlocal = new ThreadLocal<object>(() => (object)1);
Assert.Equal(1.ToString(), tlocal.ToString());
}
示例5: RunThreadLocalTest5_Dispose_Negative
public static void RunThreadLocalTest5_Dispose_Negative()
{
ThreadLocal<string> tl = new ThreadLocal<string>(() => "dispose test");
string value = tl.Value;
tl.Dispose();
Assert.Throws<ObjectDisposedException>(() => { string tmp = tl.Value; });
// Failure Case: The Value property of the disposed ThreadLocal object should throw ODE
Assert.Throws<ObjectDisposedException>(() => { bool tmp = tl.IsValueCreated; });
// Failure Case: The IsValueCreated property of the disposed ThreadLocal object should throw ODE
Assert.Throws<ObjectDisposedException>(() => { string tmp = tl.ToString(); });
// Failure Case: The ToString method of the disposed ThreadLocal object should throw ODE
}
示例6: GetTile
/// <summary>
/// Return the tile for the given ZoomLevel, X and Y coordinates.
/// </summary>
/// <param name="ZoomLevel">The zoom level.</param>
/// <param name="X">The tile x-value.</param>
/// <param name="Y">The tile y-value.</param>
/// <returns>A stream containing the tile.</returns>
public virtual Byte[] GetTile(UInt32 ZoomLevel, UInt32 X, UInt32 Y)
{
Byte[][] YCache = null;
var ThreadZoomLevel = new ThreadLocal<UInt32>(() => ZoomLevel);
var ThreadX = new ThreadLocal<UInt32>(() => X);
var ThreadY = new ThreadLocal<UInt32>(() => Y);
var XCache = TileCache[ThreadZoomLevel.Value];
if (XCache == null)
{
XCache = new Byte[(Int32) Math.Pow(2, ThreadZoomLevel.Value)][][];
TileCache[ThreadZoomLevel.Value] = XCache;
}
try
{
YCache = XCache[ThreadX.Value];
if (YCache == null)
{
YCache = new Byte[(Int32) Math.Pow(2, ThreadZoomLevel.Value)][];
XCache[ThreadX.Value] = YCache;
}
if (YCache[ThreadY.Value] == null)
{
foreach (var ActualHost in Hosts)
{
var _Url = ActualHost +
UriPattern.Replace("{zoom}", ThreadZoomLevel.ToString()).
Replace("{x}", ThreadX.ToString()).
Replace("{y}", ThreadY.ToString());
//Debug.WriteLine("Fetching: " + _Url);
try
{
var WebClient = new WebClient();
WebClient.Proxy = null;
YCache[ThreadY.Value] = WebClient.DownloadData(_Url);
}
catch (Exception e)
{
Debug.WriteLine("AMapProvider Exception: " + e);
// Try next host...
continue;
}
Debug.WriteLine("Fetched: " + _Url);
break;
}
}
return YCache[ThreadY.Value];
}
catch (IndexOutOfRangeException)
{
return null;
}
}