Click here to Skip to main content
15,896,915 members

Task Parallel Library, FxCop 1822 performance rule

Member 3660629 asked:

Open original thread
Hi,

I have a list of task

C#
List<Task> lstTasks = new List<Task>();


I am adding a method to execute into the lstTasks as below

C#
lstTasks.Add(GetTasks(() => GetTasksToExecute()));


GetTasks() method is as below

C#
private Task GetTasks<T>(Func<T> WorkMethod)
{
   return Task.Factory.StartNew(WorkMethod);
}


GetTasksToExecute method is as below

C#
private void GetTasksToExecute()
{
    //Some code here
 
}



When i executed FxCop, it gave me issue CA1822 for GetTasks() and GetTasksToExecute() method

To fix this issue, i found that these 2 method needs to be marked as static

My Question:

1. If i mark them as static will it cause any issue in TPL?
2. Is it good to exclude this rule for these 2 methods (using code line [SuppressMessage]....) ?
3. Does this rule means i need to modify all the
C#
private 
methods in my class to
C#
private static
which do not access instance member of that class?

One more important thing:

According to answer posted in the below post: "
SQL
2.As you are not using the instance from the method, it doesn't affect the status of thread safety. As the method only uses the data that is sent to it, it is thread safe.
"

Is this true?


http://stackoverflow.com/questions/6483720/code-analysis-c-sharp-net-ca1822[^]
Tags: C# (C# 4.0), .NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900