Threads Vb.net

threads vb.net
VB .NET – How to begin program AFTER form load?

Hi all,

I have a Form (Form1) and a Label (Label1).
Default: Label1.Text = “aaa”
My main objective is to change Label1.Text = “bbb” 5 sec after form load.

This is my code so far:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

System.Threading.Thread.Sleep(5000)
Label1.Text = “bbb”

End Sub

However, what happen is: the form ONLY appear after 5 sec with Label1.Text = “bbb”.
I don’t want this.
What I want is: right after I run the project, the form will APPEAR with Label1.Text = “aaa”, then after 5 sec, Label1.Text = “bbb”.

Is there any function like: Private Sub Form1_AfterLoad(ByVal…) or something?
I don’t find any in the function list.

*I don’t want to use Timer! Unless that is the very last thing I have to use.

Please help~~~

.

You almost never want to sleep in Form code.

Here’s the thing: When you create a form, or store values in a control, they don’t get painted on the screen the instant you do that. All that happens is that the form or control gets marked as ‘I need to repaint myself’. The repaint gets handled for you behind the scenes. Once there is nothing else to do, and something needs to be painted, then it gets painted.
But when you throw a Sleep in there, it mucks up the works. You don’t hit the ‘there’s nothing else to do, So I’ll paint now’ code. Because you are busy doing something else…Sleeping.

Add a timer to your form. It’s in the toolbox. Set the interval to 5000. Set it to enabled. Set an event handler for the Tick event.
In the Tick event handler, do Label1.Text = “bbb”;

Sorry, but timer is the very last thing you have to do. There really isn’t any other way.

VB.NET Tutorial 53 – MultiThreading (Visual Basic 2008/2010)


TCP/IP Sockets in C#: Practical Guide for Programmers (The Practical Guides)


TCP/IP Sockets in C#: Practical Guide for Programmers (The Practical Guides)


$18.49


“TCP/IP sockets in C# is an excellent book for anyone interested in writing network applications using Microsoft .Net frameworks. It is a unique combination of well written concise text and rich carefully selected set of working examples. For the beginner of network programming, it’s a good starting book; on the other hand professionals could also take advantage of excellent handy sample code snip…

C# Network Programming


C# Network Programming


$26.25


On its own, C# simplifies network programming. Combine it with the precise instruction found in C# Network Programming, and you’ll find that building network applications is easier and quicker than ever.This book helps newcomers get started with a look at the basics of network programming as they relate to C#, including the language’s network classes, the Winsock interface, and DNS resolution. Spe…

.NET Multithreading


.NET Multithreading


$34.95


With an understanding of the .NET framework, stable and robust multithreaded applications can be developed with minimal effort. Covering the topics related to multithreaded development, this book not only focuses on how a task is performed but also on the more important question of why these tasks are performed. The strengths and weaknesses of each approach to multithreading are analyzed so that p…

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*