Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This may be another approach. Here input is passed as parameterized Thread and return type is passed in the delegate event, so that when the thread complete that will call the Delegate. This will be fine to get result when the thread completes.</p> <pre><code> public class ThreadObject { public int i; public int j; public int result; public string Name; } public delegate void ResultDelegate(ThreadObject threadObject); public partial class Form1 : Form { public event ResultDelegate resultDelete; public Form1() { InitializeComponent(); resultDelete += new ResultDelegate(resultValue); } void resultValue(ThreadObject threadObject) { MessageBox.Show("Thread Name : " + threadObject.Name + " Thread Value : " + threadObject.result); } private void button1_Click(object sender, EventArgs e) { ThreadObject firstThreadObject = new ThreadObject(); firstThreadObject.i = 0; firstThreadObject.j = 100; firstThreadObject.Name = "First Thread"; Thread firstThread = new Thread(Fun); firstThread.Start(firstThreadObject); ThreadObject secondThreadObject = new ThreadObject(); secondThreadObject.i = 0; secondThreadObject.j = 200; secondThreadObject.Name = "Second Thread"; Thread secondThread = new Thread(Fun); secondThread.Start(secondThreadObject); } private void Fun(object parameter) { ThreadObject threadObject = parameter as ThreadObject; for (; threadObject.i &lt; threadObject.j; threadObject.i++) { threadObject.result += threadObject.i; Thread.Sleep(10); } resultValue(threadObject); } } </code></pre>
 

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