Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code in <code>Assembly1.ClassA</code> doesn't know that it's called in a separate thread from <code>Assembly2.ClassB</code>, so I'd consider it bad style to introduce a mechanism where <code>Assembly1.ClassA.task1</code> signals that it's done.</p> <p>For your scenario, it looks like you just need to call <a href="http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx" rel="nofollow">Thread.Join</a>:</p> <blockquote> <p><strong>Thread.Join Method</strong></p> <p>Blocks the calling thread until a thread terminates</p> </blockquote> <p><em>Example:</em></p> <pre><code>private void Main() { Thread newThread = new Thread(new ThreadStart(Assembly1.ClassA.Task1)); // Start thread newThread.Start(); // Wait until the invoked method returns newThread.Join(); // Do the rest ... } </code></pre> <p>Note that this is just the same as</p> <pre><code>private void Main() { // Invoke method and wait until invoked method returns Assembly1.ClassA.Task1(); // Do the rest ... } </code></pre> <p>So I guess I don't understand your question.</p> <hr> <p>Based on your updated question, I'd say that <code>Assembly1.ClassA</code> should be the one resposible for spinning up the thread:</p> <pre><code>public class ClassA { private Socket socket; private Thread thread; public void Connect() { socket = new Socket(...); socket.Connect(...); thread = new Thread(DoWork); thread.Start(); } public void Disconnect() { socket.Shutdown(SocketShutdown.Both); socket.Close(); thread.Join(); } private void DoWork() { try { while (true) { int received = socket.Receive(buffer, ...); if (received == 0) { break; } // process buffer ... } } catch (SocketException) { ... } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload