Note that there are some explanatory texts on larger screens.

plurals
  1. POSynchronisation of Two Threads
    primarykey
    data
    text
    <p>I have two threads in c#.. Now i need to wait for a particular statement to be executed before I can continue execution in the other thread which obviously is a case of synchronisation. Is there any code that can carry this out as in using an in-built method?</p> <p>This is the code example:</p> <pre><code> public void StartAccept() { try { newSock.BeginAccept(new AsyncCallback(Accepted), newSock); } catch (ArgumentException) { MessageBox.Show("Error in arguments while using begin-accept", "Error", MessageBoxButtons.OK); } catch (ObjectDisposedException) { MessageBox.Show("socket closed while using begin-accept", "Error", MessageBoxButtons.OK); } catch (SocketException) { MessageBox.Show("Error accessing socket while using begin-accept", "Error", MessageBoxButtons.OK); } catch (InvalidOperationException) { MessageBox.Show("Invalid operation while using begin-accept", "Error", MessageBoxButtons.OK); } catch (Exception) { MessageBox.Show("Exception occurred while using begin-accept", "Error", MessageBoxButtons.OK); } } </code></pre> <p>This receives data from the desired host which is selected by the code:</p> <pre><code> private void listBox1_Click(object sender, EventArgs e) { String data = (String)this.listBox1.SelectedItem; ip = Dns.GetHostAddresses(data); clientIP = new IPEndPoint(ip[0], 5555); newSock.Bind(clientIP); newSock.Listen(100); } </code></pre> <p>So in order to start receiving data I need to initialise the socket to the particular remote host which is done when i click on one of the hosts shown in the listbox. For this I need the synchronization.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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