Waiting for Thread to Join
-
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(); } }
-
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(); } }
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
-
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
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.
-
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.
The only Join that makes sense is
someOtherThread.Join()
which makes the current thread wait on someOtherThread. As I said beforeThread.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 * * *
-
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(); } }
Thread processThread = new Thread(new ThreadStart(TixChanges.ProcessChanges)); processThread.Start(); if (WaitForThreadToFinish) { processThread.Join(); }