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.

C#
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.
10,833 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,346 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 Answers by the question author, which helps users to know the answer solved the author's problem.