5 posts in this topic

Posted

Without risking the case of the 2 tasks running on the same thread and having them both stopped.

I want the first task to wait until another task finishes some action. After the second task is done with its action, it should wake the first task up and continue working from where it stopped. The first task should be waked up as well if the first task didn't do the action after a certain time.

Now, the major problem I am having is that since both are tasks, not threads, most solutions I found looks like they stop the thread, not the task only. So, it could be the case that both tasks be running on the same thread, and thus when I make the first task wait, both wait and it timeouts anyway.

Is there a clean solution around this ?

Thanks;

Share this post


Link to post
Share on other sites

Posted

Why aren't you threading the multiple tasks?

That would appear to grant greater performance and would fix the issue you're facing now O.o

Making the change would be extremely simple to do. .net is really built for multi-threading with ease.

Failing that, check out the Async and Await keywords added in .net 5, but honestly, threading is a better answer.

Share this post


Link to post
Share on other sites

Posted

Why aren't you threading the multiple tasks?

That would appear to grant greater performance and would fix the issue you're facing now O.o

Making the change would be extremely simple to do. .net is really built for multi-threading with ease.

Failing that, check out the Async and Await keywords added in .net 5, but honestly, threading is a better answer.

Switching to threading would require re-debugging a lot of the code, and I thought using the thread pool of tasks would be better, as I could have tens or potentially hundreds of tasks running, most of which are not taking much cpu, but are either idle or doing network transfers.

Share this post


Link to post
Share on other sites

Posted

Check the ContinueWith() and Wait*() methods on the Task class

MSDN

Share this post


Link to post
Share on other sites

Posted

Without risking the case of the 2 tasks running on the same thread and having them both stopped.

I want the first task to wait until another task finishes some action. After the second task is done with its action, it should wake the first task up and continue working from where it stopped. The first task should be waked up as well if the first task didn't do the action after a certain time.

If I understand you correctly, you should split the first task into two parts (two Task(T)s), so you can queue the second task after the first part, and queue the second part after the second task.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.