diff --git a/test/netstd/Client/TestClient.cs b/test/netstd/Client/TestClient.cs
index a85312b..c6b086f 100644
--- a/test/netstd/Client/TestClient.cs
+++ b/test/netstd/Client/TestClient.cs
@@ -314,8 +314,6 @@
 
             public void Execute()
             {
-                var token = CancellationToken.None;
-
                 if (done)
                 {
                     Console.WriteLine("Execute called more than once");
@@ -327,9 +325,7 @@
                     try
                     {
                         if (!transport.IsOpen)
-                        {
-                            transport.OpenAsync(token).GetAwaiter().GetResult();
-                        }
+                            transport.OpenAsync(MakeTimeoutToken()).GetAwaiter().GetResult();
                     }
                     catch (TTransportException ex)
                     {
@@ -471,17 +467,22 @@
             return retval;
         }
 
+        private static CancellationToken MakeTimeoutToken(int msec = 5000)
+        {
+            var token = new CancellationTokenSource(msec);
+            return token.Token;
+        }
+
         public static async Task<int> ExecuteClientTestAsync(ThriftTest.Client client)
         {
-            var token = CancellationToken.None;
             var returnCode = 0;
 
             Console.Write("testVoid()");
-            await client.testVoidAsync(token);
+            await client.testVoidAsync(MakeTimeoutToken());
             Console.WriteLine(" = void");
 
             Console.Write("testString(\"Test\")");
-            var s = await client.testStringAsync("Test", token);
+            var s = await client.testStringAsync("Test", MakeTimeoutToken());
             Console.WriteLine(" = \"" + s + "\"");
             if ("Test" != s)
             {
@@ -490,7 +491,7 @@
             }
 
             Console.Write("testBool(true)");
-            var t = await client.testBoolAsync((bool)true, token);
+            var t = await client.testBoolAsync((bool)true, MakeTimeoutToken());
             Console.WriteLine(" = " + t);
             if (!t)
             {
@@ -498,7 +499,7 @@
                 returnCode |= ErrorBaseTypes;
             }
             Console.Write("testBool(false)");
-            var f = await client.testBoolAsync((bool)false, token);
+            var f = await client.testBoolAsync((bool)false, MakeTimeoutToken());
             Console.WriteLine(" = " + f);
             if (f)
             {
@@ -507,7 +508,7 @@
             }
 
             Console.Write("testByte(1)");
-            var i8 = await client.testByteAsync((sbyte)1, token);
+            var i8 = await client.testByteAsync((sbyte)1, MakeTimeoutToken());
             Console.WriteLine(" = " + i8);
             if (1 != i8)
             {
@@ -516,7 +517,7 @@
             }
 
             Console.Write("testI32(-1)");
-            var i32 = await client.testI32Async(-1, token);
+            var i32 = await client.testI32Async(-1, MakeTimeoutToken());
             Console.WriteLine(" = " + i32);
             if (-1 != i32)
             {
@@ -525,7 +526,7 @@
             }
 
             Console.Write("testI64(-34359738368)");
-            var i64 = await client.testI64Async(-34359738368, token);
+            var i64 = await client.testI64Async(-34359738368, MakeTimeoutToken());
             Console.WriteLine(" = " + i64);
             if (-34359738368 != i64)
             {
@@ -535,7 +536,7 @@
 
             // TODO: Validate received message
             Console.Write("testDouble(5.325098235)");
-            var dub = await client.testDoubleAsync(5.325098235, token);
+            var dub = await client.testDoubleAsync(5.325098235, MakeTimeoutToken());
             Console.WriteLine(" = " + dub);
             if (5.325098235 != dub)
             {
@@ -543,7 +544,7 @@
                 returnCode |= ErrorBaseTypes;
             }
             Console.Write("testDouble(-0.000341012439638598279)");
-            dub = await client.testDoubleAsync(-0.000341012439638598279, token);
+            dub = await client.testDoubleAsync(-0.000341012439638598279, MakeTimeoutToken());
             Console.WriteLine(" = " + dub);
             if (-0.000341012439638598279 != dub)
             {
@@ -555,7 +556,7 @@
             Console.Write("testBinary(" + BytesToHex(binOut) + ")");
             try
             {
-                var binIn = await client.testBinaryAsync(binOut, token);
+                var binIn = await client.testBinaryAsync(binOut, MakeTimeoutToken());
                 Console.WriteLine(" = " + BytesToHex(binIn));
                 if (binIn.Length != binOut.Length)
                 {
@@ -601,7 +602,7 @@
             o.Byte_thing = (sbyte)1;
             o.I32_thing = -3;
             o.I64_thing = -5;
-            var i = await client.testStructAsync(o, token);
+            var i = await client.testStructAsync(o, MakeTimeoutToken());
             Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}");
 
             // TODO: Validate received message
@@ -610,7 +611,7 @@
             o2.Byte_thing = (sbyte)1;
             o2.Struct_thing = o;
             o2.I32_thing = 5;
-            var i2 = await client.testNestAsync(o2, token);
+            var i2 = await client.testNestAsync(o2, MakeTimeoutToken());
             i = i2.Struct_thing;
             Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}");
 
@@ -635,7 +636,7 @@
             }
             Console.Write("})");
 
-            var mapin = await client.testMapAsync(mapout, token);
+            var mapin = await client.testMapAsync(mapout, MakeTimeoutToken());
 
             Console.Write(" = {");
             first = true;
@@ -675,7 +676,7 @@
             }
             Console.Write("})");
 
-            var listin = await client.testListAsync(listout, token);
+            var listin = await client.testListAsync(listout, MakeTimeoutToken());
 
             Console.Write(" = {");
             first = true;
@@ -716,7 +717,7 @@
             }
             Console.Write("})");
 
-            var setin = await client.testSetAsync(setout, token);
+            var setin = await client.testSetAsync(setout, MakeTimeoutToken());
 
             Console.Write(" = {");
             first = true;
@@ -736,7 +737,7 @@
 
 
             Console.Write("testEnum(ONE)");
-            var ret = await client.testEnumAsync(Numberz.ONE, token);
+            var ret = await client.testEnumAsync(Numberz.ONE, MakeTimeoutToken());
             Console.WriteLine(" = " + ret);
             if (Numberz.ONE != ret)
             {
@@ -745,7 +746,7 @@
             }
 
             Console.Write("testEnum(TWO)");
-            ret = await client.testEnumAsync(Numberz.TWO, token);
+            ret = await client.testEnumAsync(Numberz.TWO, MakeTimeoutToken());
             Console.WriteLine(" = " + ret);
             if (Numberz.TWO != ret)
             {
@@ -754,7 +755,7 @@
             }
 
             Console.Write("testEnum(THREE)");
-            ret = await client.testEnumAsync(Numberz.THREE, token);
+            ret = await client.testEnumAsync(Numberz.THREE, MakeTimeoutToken());
             Console.WriteLine(" = " + ret);
             if (Numberz.THREE != ret)
             {
@@ -763,7 +764,7 @@
             }
 
             Console.Write("testEnum(FIVE)");
-            ret = await client.testEnumAsync(Numberz.FIVE, token);
+            ret = await client.testEnumAsync(Numberz.FIVE, MakeTimeoutToken());
             Console.WriteLine(" = " + ret);
             if (Numberz.FIVE != ret)
             {
@@ -772,7 +773,7 @@
             }
 
             Console.Write("testEnum(EIGHT)");
-            ret = await client.testEnumAsync(Numberz.EIGHT, token);
+            ret = await client.testEnumAsync(Numberz.EIGHT, MakeTimeoutToken());
             Console.WriteLine(" = " + ret);
             if (Numberz.EIGHT != ret)
             {
@@ -781,7 +782,7 @@
             }
 
             Console.Write("testTypedef(309858235082523)");
-            var uid = await client.testTypedefAsync(309858235082523L, token);
+            var uid = await client.testTypedefAsync(309858235082523L, MakeTimeoutToken());
             Console.WriteLine(" = " + uid);
             if (309858235082523L != uid)
             {
@@ -791,7 +792,7 @@
 
             // TODO: Validate received message
             Console.Write("testMapMap(1)");
-            var mm = await client.testMapMapAsync(1, token);
+            var mm = await client.testMapMapAsync(1, MakeTimeoutToken());
             Console.Write(" = {");
             foreach (var key in mm.Keys)
             {
@@ -817,7 +818,7 @@
             insane.Xtructs = new List<Xtruct>();
             insane.Xtructs.Add(truck);
             Console.Write("testInsanity()");
-            var whoa = await client.testInsanityAsync(insane, token);
+            var whoa = await client.testInsanityAsync(insane, MakeTimeoutToken());
             Console.Write(" = {");
             foreach (var key in whoa.Keys)
             {
@@ -880,14 +881,14 @@
             var arg4 = Numberz.FIVE;
             long arg5 = 5000000;
             Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + ",{" + string.Join(",", tmpMultiDict) + "}," + arg4 + "," + arg5 + ")");
-            var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, token);
+            var multiResponse = await client.testMultiAsync(arg0, arg1, arg2, multiDict, arg4, arg5, MakeTimeoutToken());
             Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing
                           + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n");
 
             try
             {
                 Console.WriteLine("testException(\"Xception\")");
-                await client.testExceptionAsync("Xception", token);
+                await client.testExceptionAsync("Xception", MakeTimeoutToken());
                 Console.WriteLine("*** FAILED ***");
                 returnCode |= ErrorExceptions;
             }
@@ -908,7 +909,7 @@
             try
             {
                 Console.WriteLine("testException(\"TException\")");
-                await client.testExceptionAsync("TException", token);
+                await client.testExceptionAsync("TException", MakeTimeoutToken());
                 Console.WriteLine("*** FAILED ***");
                 returnCode |= ErrorExceptions;
             }
@@ -925,7 +926,7 @@
             try
             {
                 Console.WriteLine("testException(\"ok\")");
-                await client.testExceptionAsync("ok", token);
+                await client.testExceptionAsync("ok", MakeTimeoutToken());
                 // OK
             }
             catch (Exception ex)
@@ -938,7 +939,7 @@
             try
             {
                 Console.WriteLine("testMultiException(\"Xception\", ...)");
-                await client.testMultiExceptionAsync("Xception", "ignore", token);
+                await client.testMultiExceptionAsync("Xception", "ignore", MakeTimeoutToken());
                 Console.WriteLine("*** FAILED ***");
                 returnCode |= ErrorExceptions;
             }
@@ -959,7 +960,7 @@
             try
             {
                 Console.WriteLine("testMultiException(\"Xception2\", ...)");
-                await client.testMultiExceptionAsync("Xception2", "ignore", token);
+                await client.testMultiExceptionAsync("Xception2", "ignore", MakeTimeoutToken());
                 Console.WriteLine("*** FAILED ***");
                 returnCode |= ErrorExceptions;
             }
@@ -980,7 +981,7 @@
             try
             {
                 Console.WriteLine("testMultiException(\"success\", \"OK\")");
-                if ("OK" != (await client.testMultiExceptionAsync("success", "OK", token)).String_thing)
+                if ("OK" != (await client.testMultiExceptionAsync("success", "OK", MakeTimeoutToken())).String_thing)
                 {
                     Console.WriteLine("*** FAILED ***");
                     returnCode |= ErrorExceptions;
@@ -996,7 +997,7 @@
             var sw = new Stopwatch();
             sw.Start();
             Console.WriteLine("Test Oneway(1)");
-            await client.testOnewayAsync(1, token);
+            await client.testOnewayAsync(1, MakeTimeoutToken());
             sw.Stop();
             if (sw.ElapsedMilliseconds > 1000)
             {
@@ -1008,6 +1009,7 @@
             var times = 50;
             sw.Reset();
             sw.Start();
+            var token = MakeTimeoutToken(20000);
             for (var k = 0; k < times; ++k)
                 await client.testVoidAsync(token);
             sw.Stop();
