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. Passing Parameter Method into a Thread, Help!

Passing Parameter Method into a Thread, Help!

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 3 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.
  • P Offline
    P Offline
    Patricio Tapia
    wrote on last edited by
    #1

    public delegate void updatevalores(int total); public partial class FormConexiones : Form { private int procesosactuales = 0; public FormConexiones() { InitializeComponent(); } private void FormConexiones_Load(object sender, EventArgs e) { procesos proces = new procesos(); Thread pid = new Thread(new ThreadStart(proces.iniciar(new updatevalores(actualizarv)))); pid.Start(); } public void actualizarv(int total) { procesosactuales = total; } } Another Class: class procesos { { struct sproceso { public int id; public string NombreProceso; public string DirProceso; public string FileProceso; public DateTime tiempoinicio; } ArrayList listaprocesos = new ArrayList(); bool existeproces = false; bool coincide = false; Timer nuevotiempo = new Timer(); public void iniciar(updatevalores procesoact) { nuevotiempo.Elapsed += new ElapsedEventHandler(TiempoEjecutar); nuevotiempo.Interval = 5000; nuevotiempo.Enabled = true; } } The Line Thread pid = new Thread(new ThreadStart(proces.iniciar(new updatevalores(actualizarv)))); has give me an error. How i can pass values to proces.iniciar method?????????? Thanks

    M 1 Reply Last reply
    0
    • P Patricio Tapia

      public delegate void updatevalores(int total); public partial class FormConexiones : Form { private int procesosactuales = 0; public FormConexiones() { InitializeComponent(); } private void FormConexiones_Load(object sender, EventArgs e) { procesos proces = new procesos(); Thread pid = new Thread(new ThreadStart(proces.iniciar(new updatevalores(actualizarv)))); pid.Start(); } public void actualizarv(int total) { procesosactuales = total; } } Another Class: class procesos { { struct sproceso { public int id; public string NombreProceso; public string DirProceso; public string FileProceso; public DateTime tiempoinicio; } ArrayList listaprocesos = new ArrayList(); bool existeproces = false; bool coincide = false; Timer nuevotiempo = new Timer(); public void iniciar(updatevalores procesoact) { nuevotiempo.Elapsed += new ElapsedEventHandler(TiempoEjecutar); nuevotiempo.Interval = 5000; nuevotiempo.Enabled = true; } } The Line Thread pid = new Thread(new ThreadStart(proces.iniciar(new updatevalores(actualizarv)))); has give me an error. How i can pass values to proces.iniciar method?????????? Thanks

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, This[^] should help!

      All the best, Martin

      P 1 Reply Last reply
      0
      • M Martin 0

        Hello, This[^] should help!

        All the best, Martin

        P Offline
        P Offline
        Patricio Tapia
        wrote on last edited by
        #3

        public delegate void updatevalores(int total); public partial class FormConexiones : Form { private int procesosactuales = 0; public FormConexiones() { InitializeComponent(); } private void FormConexiones_Load(object sender, EventArgs e) { procesos proces = new procesos(); Thread pid = new Thread(new ParameterizedThreadStart(proces.iniciar)); pid.Start(new updatevalores(actualizarv)); } public void actualizarv(int total) { procesosactuales = total; } } Give me an error with ParameterizedThreadStart(proces.iniciar) The error is: none overload correspond 'iniciar' match with 'System.Threading.ParameterizedThreadStart' delegate what the :mad:

        P 1 Reply Last reply
        0
        • P Patricio Tapia

          public delegate void updatevalores(int total); public partial class FormConexiones : Form { private int procesosactuales = 0; public FormConexiones() { InitializeComponent(); } private void FormConexiones_Load(object sender, EventArgs e) { procesos proces = new procesos(); Thread pid = new Thread(new ParameterizedThreadStart(proces.iniciar)); pid.Start(new updatevalores(actualizarv)); } public void actualizarv(int total) { procesosactuales = total; } } Give me an error with ParameterizedThreadStart(proces.iniciar) The error is: none overload correspond 'iniciar' match with 'System.Threading.ParameterizedThreadStart' delegate what the :mad:

          P Offline
          P Offline
          Patricio Tapia
          wrote on last edited by
          #4

          damn i forget to read: This is simple, but only accepts a single parameter and isn't type-safe (just like the options when using thread pool threads) :->

          M 1 Reply Last reply
          0
          • P Patricio Tapia

            damn i forget to read: This is simple, but only accepts a single parameter and isn't type-safe (just like the options when using thread pool threads) :->

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            So you are fine with that?

            All the best, Martin

            P 1 Reply Last reply
            0
            • M Martin 0

              So you are fine with that?

              All the best, Martin

              P Offline
              P Offline
              Patricio Tapia
              wrote on last edited by
              #6

              Yep Works Fine: procesos proces = new procesos(); ThreadStart inipro = delegate { proces.iniciar(new updatevalores(actualizarv)); }; new Thread(inipro).Start(); Ok, so much battle with Thread and asyncronic querys... time to rest :zzz: thanks for all :D

              M 1 Reply Last reply
              0
              • P Patricio Tapia

                Yep Works Fine: procesos proces = new procesos(); ThreadStart inipro = delegate { proces.iniciar(new updatevalores(actualizarv)); }; new Thread(inipro).Start(); Ok, so much battle with Thread and asyncronic querys... time to rest :zzz: thanks for all :D

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #7

                Sleep well! You are wellcome!

                All the best, Martin

                K 1 Reply Last reply
                0
                • M Martin 0

                  Sleep well! You are wellcome!

                  All the best, Martin

                  K Offline
                  K Offline
                  KANGAROO_
                  wrote on last edited by
                  #8

                  y me getting also feel to sleep.............. a very long conversation to a simple problem... :zzz:

                  Thanks and regards manoj Kumar Jha

                  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