Note that there are some explanatory texts on larger screens.

plurals
  1. POExecute the last thread in threadloop
    primarykey
    data
    text
    <p>I am implementing a comic reader in C# 4.0, and browsing from one image to the next takes some time because of some processes I implemented. </p> <p>Therefore, I implemented it in such a way that the UI thread will show first the unprocessed image whilst the background thread is processing the image and will later replace the unprocessed image.</p> <p>It all works fine but now, some users will crazily like to click next image continusly and this causes the background worker to processes all those clicks and display all the images.</p> <p>WHAT I WANT: if a user clicks multiple times, I want the background worker to process the last thread only.</p> <p>WHAT I HAVE DONE: Now, I have implemented a function to check the number of active threads, if the active threads is greater than 1, background thread will not process but returns the previous image(THAT IS NOT GOOD, because the unprocessed image will be one index ahead)</p> <p>If you have idea please explain to me like a beginner!</p> <pre><code>private void button4_Click(object sender, EventArgs e) { Bitmap b = new Bitmap(this.CurrImage); if (!shutdown) { process_updateThread = new Thread(new ThreadStart(process_update)); process_updateThread.Start(); } pictureBox1.Image = b; //image will be replaced by worker thread image pictureBox1.Location = ImageEdit.CalculateLocationImage(b); SetBackColor(b); ShowPageCount(); updateNavButtons(); } void StopThread() { if(((IEnumerable)System.Diagnostics.Process.GetCurrentProcess().Threads).OfType&lt;System.Diagnostics.ProcessThread&gt;() .Where(t =&gt; t.ThreadState == System.Diagnostics.ThreadState.Running).Count() &gt; 1) shutdown = true; else shutdown = false; } </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.
 

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