C# using command, task, httpclient objects

diego gutierrez 161 Reputation points
2022-09-16T22:29:08.497+00:00

Hi everyone.

In the code below I have some questions.

  1. I am working with using command for HttpClient to dispose the object, Should I use using command also for task, task2, task3 objects? I mean, Do I need to dispose these task objects?
  2. Is there a way to use only one task object instead of three task objects? In this case task, task2 and task 3

242005-test.jpg

Thanks in advance.

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Sreeju Nair 12,756 Reputation points
    2022-09-18T10:36:58.873+00:00

    I recommend you to go through the following article that explains why you should not bother disposing task objects.

    https://devblogs.microsoft.com/pfxteam/do-i-need-to-dispose-of-tasks/

    Regarding using the same variable, for task1, 2 & 3, it is possible. you can have a Task variable say "task" of type Task and use it.

    Hope this helps

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.