c# - Concurrency in .net for a function -


i have following code being run in multi-threading business logic:

using system; using system.threading.tasks;  namespace test {     class program     {         static void main(string[] args)         {             var biz1 = new biz { = 1, value = "a" };             var biz2 = new biz { = 2, value = "b" };             var foo = new foo();              //thread 1             new task(() => foo.run(biz1)).start();             //thread 2             new task(() => foo.run(biz2)).start();             //more threads here other biz objects....              console.read();         }     }      public class biz     {         public int { get; set; }         public string value { get; set; }     }      public class foo     {         public void run(biz biz)         {             //base on biz object task here          }     } } 

the biz object not being changed @ anytime during threading

questions:

  • is foo.run thread safe?
  • is better instantiate individual foo object run each biz object (the run function within foo)?

  • is foo.run thread safe?

it sounds foo.run() safe, depends on other data accessed of course.

  • is better instantiate individual foo object run each biz object (the run function within foo)?

assuming safe, ie not use instance data of foo, run() , should static. @ least convey better message reader.

public static class foo {     public static void run(biz biz)     {         //base on biz object task here      } } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -