Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UI & Thread Management All In One
#3
I will be demonstrating the source of this soon as well. I'm just working on implementing this into an existing application that I have to improve performance if i'm going to multi-thread and persist UI modifications on various threads.

That button click shown in the GIF (while the label is still counting) is actually ignored, which is what I was trying to demonstrate there, but unfortunately I can't really do that.

This is to prevent multiple threads doing the same function from being started at the same time while a pre-existing thread is already functional.

The way this concept works:

-A thread is started (counts the label control text value upwards)
-The thread alternates it's process using the breaks in between (when it's not updating the label; fraction of a second) to update the UI, keeping it functional
-The thread goes back to updating the label which takes precedence
-Repeat

-While thread is still functional, disable closing of form or starting a new thread which does the same thing (count the label text value upwards)

In the end you're utilizing the full potential of your thread and avoiding wait times that do nothing. And you can use threads that update the UI without it's heavy loaded process noticeably freezing the UI at all.

THE BIG DIFFERENCE HERE: This doesn't use a control timer, and the updates are from a full process chunked out into smaller parts. Resuming the original process instead of starting a new one each time.

Code:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label1.Text = "0"
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = CStr(CInt(Label1.Text) + 1)
    End Sub

You can do that, but this is more of a new process each time in essence.

For example, say you want to load all the values of an array into a textbox. The method of using a timer like that may not help you, as a timer tick is initiated as ONE process each time, so you may end up with it loading the array into the textbox each time the timer ticks.

I'm having a hard time explaining this, but the way the method works above from what I posted, you build onto an already existing process.

It's like having a construction worker, build a house, and giving them a lunch break to replenish. That lunch break time is essentially needed to update the UI, but you're not building a house each time, you're building on the same house in chunks, and allowing something else to happen in between the initial start and end process.
Reply


Messages In This Thread
RE: A Bit Of Affinity & Thread Management All In One - by AceInfinity - 03-16-2012, 06:17 PM
RE: UI & Thread Management All In One - by kpn37z - 06-24-2012, 04:31 AM
RE: UI & Thread Management All In One - by Kewlz - 06-24-2012, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [VB.NET] System.Management Version 2.0.0.0 without Import Make App [SRC] Imports System.Net 0 2,115 05-13-2011, 11:32 AM
Last Post: Imports System.Net

Forum Jump:


Users browsing this thread: 1 Guest(s)