Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. parameter

parameter

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    messages
    wrote on last edited by
    #1

    Hi everyone

    Can we use of this way for sending parameters to a thread or threads or its wrong?

        static void test(params object\[\] a)
        {
    
            foreach (var d in a)
                Console.WriteLine(d);
        }
    
        static void Main(string\[\] args)
        {
            Thread t = new Thread(() => test("an example!","second",125));
            t.Start();
    

    }

    T 1 Reply Last reply
    0
    • M messages

      Hi everyone

      Can we use of this way for sending parameters to a thread or threads or its wrong?

          static void test(params object\[\] a)
          {
      
              foreach (var d in a)
                  Console.WriteLine(d);
          }
      
          static void Main(string\[\] args)
          {
              Thread t = new Thread(() => test("an example!","second",125));
              t.Start();
      

      }

      T Offline
      T Offline
      testy_proconsul
      wrote on last edited by
      #2

      Yes, for sure. It also depends on the complexity or type of your architecture, maybe there exist design patterns. But independent of that: yes, you can do it like that. But you have to take care if you use objects as parameters. If you write into these objects from within your "test" method, the access has to be synchronized (ensuring that only one thread can write data at the same time).

      solidIT.de - under construction Components for Microsoft .Net audittrail, objectcomparer, deepcopy and much more ... alternatively: objectcomparer.codeplex.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups