Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Multithreading does not automagically make your program run faster, and <code>Thread.Join</code> simply waits for the thread to complete. </p> <p>Basically if your main thread cannot continue until the thread has completed, you should not use multithreading.</p> <p>Examples of where multithreading does fit:</p> <ul> <li>when trying to download information from several locations, you can let multiple threads wait for data from one location each</li> <li>when you want to perform a time-consuming task while keeping the user interface responsive</li> </ul> <p>The second example may be the case here, but <code>Thread.Join</code> is a blocking operation: it still stops the user interface from being updated while the thread is working. In that case, you'd have to let the thread inform the main thread of its completion.</p> <p>I don't know on what platform you're working here, but for instance on windows forms, the <code>Form</code> class has an <code>Invoke</code> method which lets you call a method on that form's thread:</p> <pre><code>class TheForm { // the method running in a separate thread void myThread() { // do the time consuming work byte[] myData = ProcessData(); // send data to the main thread Invoke(new Action&lt;byte[]&gt;(ThreadCompleted), myData); } // will be executed in the main thread void ThreadCompleted(byte[] data) { // process the data } } </code></pre> <p>About global variables and multithreading: any thread can access them, but there's no telling <em>which</em> thread accesses them <em>when</em>. If you can, you should avoid letting multiple threads access them, or use a <code>lock</code> mechanism to protect them.</p>
    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.
 

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