Share via

C# using command, task, httpclient objects

diego gutierrez 161 Reputation points
Sep 16, 2022, 10:29 PM

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.
11,221 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sreeju Nair 12,536 Reputation points
    Sep 18, 2022, 10:36 AM

    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.