Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f07dd6a

Browse files
committed
Change to use tcs to avoid debugger breakpoints.
1 parent 503d28b commit f07dd6a

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/ServiceStack.Text/HttpUtils.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,24 +348,35 @@ public static Task<string> SendStringToUrlAsync(this string url, string method =
348348
}
349349

350350
var taskWebRes = webReq.GetResponseAsync();
351-
return taskWebRes
352-
.ContinueWith(task =>
351+
var tcs = new TaskCompletionSource<string>();
352+
353+
taskWebRes.ContinueWith(task =>
354+
{
355+
if (task.Exception != null)
353356
{
354-
if (task.Exception != null)
355-
throw task.Exception;
357+
tcs.SetException(task.Exception);
358+
return;
359+
}
360+
if (task.IsCanceled)
361+
{
362+
tcs.SetCanceled();
363+
return;
364+
}
356365

357-
var webRes = task.Result;
358-
if (responseFilter != null)
359-
{
360-
responseFilter((HttpWebResponse)webRes);
361-
}
366+
var webRes = task.Result;
367+
if (responseFilter != null)
368+
{
369+
responseFilter((HttpWebResponse)webRes);
370+
}
362371

363-
using (var stream = webRes.GetResponseStream())
364-
using (var reader = new StreamReader(stream))
365-
{
366-
return reader.ReadToEnd();
367-
}
368-
}, TaskContinuationOptions.NotOnCanceled);
372+
using (var stream = webRes.GetResponseStream())
373+
using (var reader = new StreamReader(stream))
374+
{
375+
tcs.SetResult(reader.ReadToEnd());
376+
}
377+
});
378+
379+
return tcs.Task;
369380
}
370381

371382
public static string SendStringToUrl(this string url, string method = null,

0 commit comments

Comments
 (0)