Questions tagged [continuewith]
45 questions
5
votes
2 answers
Exceptions are not caught with ContinueWith?
Using Visual Studio 2015, targeting FW 4 (testing unobservable exceptions under FW 4):
I'm expecting this code:
static void Main(string[] args)
{
try
{
Task.Factory.StartNew(() => Console.WriteLine(1))
.ContinueWith(t =>…

Royi Namir
- 144,742
- 138
- 468
- 792
4
votes
1 answer
Using ContinueWith() on an awaited task and calling Task.Result inside
I came across the following code that uses the ContinueWith() to wait for the result.
public async Task GetUser()
{
return await _serviceRepo.GetUserAsync()
.ContinueWith(task =>
{
return task.Result;
…

Stack Undefined
- 1,050
- 1
- 14
- 23
3
votes
2 answers
F# Async Equivalent of Task.ContinueWith
I have been implementing a [] attribute for some of our larger .NET solutions that will allow configurable analytics to be easily added to any functions/methods that are considered important. I'm using Fody and the MethodBoundaryAspect to…

Aaron M. Eshbach
- 6,380
- 12
- 22
3
votes
1 answer
C# Chained ContinueWith Not Waiting for Previous Task to Complete
I am testing the asynchronousity of C# async/await and came across a surprise where the subsequent code for ContinueWith does not wait for the previous task to complete:
public async Task SampleAsyncMethodAsync(int number,string id)
{
…

TropicalFruitz
- 33
- 3
2
votes
2 answers
Async Await and ContinueWith not working as expected
I have the following code that runs on .NET Standard 2.0:
public static Task TryRunAsync(this IJob job,
CancellationToken cancellationToken = default(CancellationToken))
{
return…

Blake Niemyjski
- 3,432
- 3
- 25
- 41
2
votes
1 answer
Convert Task to Task (Wrap Task with return type of T)
I've read this question but in my case its simpler because I don't have to use Result property. so I was wondering if I can go with simpler approach than what is provided by Stephen Cleary's answer.
Suppose I have this simple interface.
internal…

M.kazem Akhgary
- 18,645
- 8
- 57
- 118
1
vote
2 answers
ContinueWith for a Task of unknown generic type
I have a method that gets a Task where T is unknown at compile time and an IAsyncDisposable. I need to return a Task which automatically disposes the disposable object after the original task has been completed.
This is what I came up with so…

wertzui
- 5,148
- 3
- 31
- 51
1
vote
1 answer
When are .NET TaskCompletionSource Tasks eligible for GC (not rooted)?
I'm writing a utility class for some asynchronous code, and I want to ensure that I don't create memory leaks with the design. Suppose I've got code which executes similarly to the class below. (Obviously you wouldn't write code that works like…

aaronburro
- 504
- 6
- 15
1
vote
0 answers
Task continuation unexpected behaviour
please take a look at the following code:
So, I grab the current context (WinForms thread), start a new task with that context, and attach a synchonous continuation with the Default task scheduler. As far as I understand, a continuation should start…

lilo0
- 895
- 9
- 12
1
vote
1 answer
It takes more than a few seconds for a task to start running
I'm developing an application using WPF and C#.
I have the following code:
var tokenSource = new CancellationTokenSource();
CancellationToken token = tokenSource.Token;
Task task = Task.Factory.StartNew(() =>
{
…

Cod Fish
- 917
- 1
- 8
- 37
1
vote
1 answer
TPL nested tasks or ContinueWith()? Where to put WhenAll?
Nested tasks or ContinueWith()? Where to put WhenAll()
I am new to TPL and I'd like some guidance on how to accomplish this the RIGHT way. I have read up on the TPL library with these resources and I'm still unclear of the best approach:
Parallel…

Larry Moody
- 11
- 2
1
vote
1 answer
C#: How to catch cancellation exception in task.continuewith
I have tried many ways but failed to catch the cancellation exception in task.ContinueWith. Is there anything wrong here:
CancellationTokenSource tokenSource = new CancellationTokenSource();
Task task = new Task( ()=> { Thread.Sleep(1000);…

derek
- 9,358
- 11
- 53
- 94
0
votes
0 answers
is possible to run code asynchronously in ContinueWith(), when ContinueWith uses FromCurrentSynchronizationContext TaskScheduler?
Is possible to somehow force action calcData to run asynchronously in ContinueWith?
Action loadData = () => { Thread.Sleep(200); Console.WriteLine("Used thread: " + Thread.CurrentThread.ManagedThreadId); /* Load data from DB*/ };
Action showData =…

1000Bugy
- 105
- 1
- 8
0
votes
1 answer
Why this weird results when playing around with task and continuewith
Dim d = 1
Dim task1 = Task.Delay(1)
Dim task2 = Task.Delay(2)
Dim task4 = Sub() d += 1 'Type of task4 is delegate sub
Dim task3 = task1.ContinueWith(task2) ' error
Dim task5 = task1.ContinueWith(Sub() d += 1) 'works
Dim…

user4951
- 32,206
- 53
- 172
- 282
0
votes
1 answer
Problem with running tasks sequentially using ContinueWith
I want to start a proccess by checking toggleButton and after finishing proccess toggleButton be Unchecked.
Here is my code.
Proccess.xaml :

stack CVL
- 15
- 6