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. Waiting for Thread to Join

Waiting for Thread to Join

Scheduled Pinned Locked Moved C#
mysqlquestion
5 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.
  • B Offline
    B Offline
    Brad Wick
    wrote on last edited by
    #1

    I have the following function, but I am trying to have the application wait until the thread completes before it moves on but the application just appears to lock. can someone tell me what I might be doing wrong? private void UploadTicketChnges(bool WaitForThreadToFinish) { TicketChanges TixChanges = new TicketChanges(mysql, mysqlcmd); TixChanges.AppEventID = AppEventID; TixChanges.AppMemberEmail = AppMemberEmail; TixChanges.AppMemberPassword = AppMemberPassword; TixChanges.configAPIURL = configAPIURL; TixChanges.configDatabaseTable = configDatabaseTable; new Thread(new ThreadStart(TixChanges.ProcessChanges)).Start(); if (WaitForThreadToFinish) { // wait for all the threads to finish Thread.CurrentThread.Join(); } }

    L S 2 Replies Last reply
    0
    • B Brad Wick

      I have the following function, but I am trying to have the application wait until the thread completes before it moves on but the application just appears to lock. can someone tell me what I might be doing wrong? private void UploadTicketChnges(bool WaitForThreadToFinish) { TicketChanges TixChanges = new TicketChanges(mysql, mysqlcmd); TixChanges.AppEventID = AppEventID; TixChanges.AppMemberEmail = AppMemberEmail; TixChanges.AppMemberPassword = AppMemberPassword; TixChanges.configAPIURL = configAPIURL; TixChanges.configDatabaseTable = configDatabaseTable; new Thread(new ThreadStart(TixChanges.ProcessChanges)).Start(); if (WaitForThreadToFinish) { // wait for all the threads to finish Thread.CurrentThread.Join(); } }

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Brad Wick wrote:

      Thread.CurrentThread.Join();

      "Thread.Join() blocks the calling thread until a thread terminates." :confused: you want the current thread to wait until the current thread has finished :confused:

      Luc Pattyn [Forum Guidelines] [My Articles]


      this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


      B 1 Reply Last reply
      0
      • L Luc Pattyn

        Brad Wick wrote:

        Thread.CurrentThread.Join();

        "Thread.Join() blocks the calling thread until a thread terminates." :confused: you want the current thread to wait until the current thread has finished :confused:

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        B Offline
        B Offline
        Brad Wick
        wrote on last edited by
        #3

        Yes I would like the main application that calls the thread to wait until its finished. I know this is not what threading is all about, but when I call the thread for the very first time I want it to wait until its completed. The other time's it is called is inside a timer which I don't care about it waiting until it's finished.

        L 1 Reply Last reply
        0
        • B Brad Wick

          Yes I would like the main application that calls the thread to wait until its finished. I know this is not what threading is all about, but when I call the thread for the very first time I want it to wait until its completed. The other time's it is called is inside a timer which I don't care about it waiting until it's finished.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          The only Join that makes sense is someOtherThread.Join() which makes the current thread wait on someOtherThread. As I said before Thread.CurrentThread.Join() makes no sense, it makes the current thread wait until the current thread is finished, which is never since it is waiting... :) Luc Pattyn [[Forum Guidelines]](http://www.codeproject.com/scrapbook/ForumGuidelines.asp) [[My Articles]](http://www.codeproject.com/script/articles/list_articles.asp?userid=648011) * * * this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google * * *

          1 Reply Last reply
          0
          • B Brad Wick

            I have the following function, but I am trying to have the application wait until the thread completes before it moves on but the application just appears to lock. can someone tell me what I might be doing wrong? private void UploadTicketChnges(bool WaitForThreadToFinish) { TicketChanges TixChanges = new TicketChanges(mysql, mysqlcmd); TixChanges.AppEventID = AppEventID; TixChanges.AppMemberEmail = AppMemberEmail; TixChanges.AppMemberPassword = AppMemberPassword; TixChanges.configAPIURL = configAPIURL; TixChanges.configDatabaseTable = configDatabaseTable; new Thread(new ThreadStart(TixChanges.ProcessChanges)).Start(); if (WaitForThreadToFinish) { // wait for all the threads to finish Thread.CurrentThread.Join(); } }

            S Offline
            S Offline
            Steve Hansen
            wrote on last edited by
            #5

            Thread processThread = new Thread(new ThreadStart(TixChanges.ProcessChanges)); processThread.Start(); if (WaitForThreadToFinish) { processThread.Join(); }

            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