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. each button click starting a new thread

each button click starting a new thread

Scheduled Pinned Locked Moved C#
5 Posts 4 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.
  • L Offline
    L Offline
    lane0p2
    wrote on last edited by
    #1

    Hi All, i'm trying to write a program where the button1_Click event will start a new thread and everything within the button1_Click runs within this thread, rather than starting new threads within the button1_Click. so, i want this: thrd_1 = new Thread(new ThreadStart(button1_Click)); private void button1_Click(object sender, eventArgs e) { things to do 1 things to do 2 } rather than private void button1_Click(object sender, eventArgs e) { thrd_1.start() thrd_2.start() } i hope this makes sense! Many thanks, Phil

    P 1 Reply Last reply
    0
    • L lane0p2

      Hi All, i'm trying to write a program where the button1_Click event will start a new thread and everything within the button1_Click runs within this thread, rather than starting new threads within the button1_Click. so, i want this: thrd_1 = new Thread(new ThreadStart(button1_Click)); private void button1_Click(object sender, eventArgs e) { things to do 1 things to do 2 } rather than private void button1_Click(object sender, eventArgs e) { thrd_1.start() thrd_2.start() } i hope this makes sense! Many thanks, Phil

      P Offline
      P Offline
      Pr teek B h
      wrote on last edited by
      #2

      so what exactly is your question? from what it looks like you already have the answer. Prateek

      L 1 Reply Last reply
      0
      • P Pr teek B h

        so what exactly is your question? from what it looks like you already have the answer. Prateek

        L Offline
        L Offline
        lane0p2
        wrote on last edited by
        #3

        Hi, thanks for replying so quickly. the problem is it won't compile. it errors saying - No overload for button1_Click matches delegate 'System.Threading.ThreadStart.

        L M 2 Replies Last reply
        0
        • L lane0p2

          Hi, thanks for replying so quickly. the problem is it won't compile. it errors saying - No overload for button1_Click matches delegate 'System.Threading.ThreadStart.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You must do it like in the second solution, the first one won't work. regards

          1 Reply Last reply
          0
          • L lane0p2

            Hi, thanks for replying so quickly. the problem is it won't compile. it errors saying - No overload for button1_Click matches delegate 'System.Threading.ThreadStart.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            The error message explains it... The ThreadStart delegate looks like this:

            public delegate void ThreadStart()

            Are you looking for something like this?

            private void button1_Click(object sender, eventArgs e)
            {
            thrd_1 = new Thread(new ThreadStart(button1_Clickthread));
            thrd_1.start()
            }

            private void button1_Clickthread()
            {
            things to do 1
            things to do 2
            }

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            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