Skip to content

How to wait all data to be sent on stream before main thread end program #2207

Answered by nibanks
ami-GS asked this question in Q&A
Discussion options

You must be logged in to vote

There are a couple ways you might achieve this, but all of them rely on either explicitly or implicitly waiting on the "shutdown complete" event before closing the object(s). The simplest way for a fire-and-forget style protocol would be to so something like the sample. You will notice the RunClient simply starts the connection async and then returns, eventually calling RegistrationClose. The start will asynchronously kick off other work, like opening and sending stream data. The main thread that calls RegistrationClose will block (wait) until the connection has been closed; so as long as the code cleans up asynchronously, correctly, eventually everything completes nicely and then returns…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ami-GS
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants