blinking label

  • Thread starter Thread starter giannis
  • Start date Start date
How can i make a blinking label ? Is this possible ?

Never tried this, but you could have a timer, and for each tick event,
change the visibility (or colour, or whatever) of the label in
question.
 
Never tried this, but you could have a timer, and for each tick event,
change the visibility (or colour, or whatever) of the label in
question.

This should work. For Windows Forms applications,
'System.Windows.Forms.Timer' (available in the toolbox) is the right choice.
 
Herfried said:
This should work. For Windows Forms applications,
'System.Windows.Forms.Timer' (available in the toolbox) is the right
choice.

I wrote at the Tick event the :

Me.Label.Visible = Not Me.Label.Visible

but nothing happened :(
 
giannis said:
I wrote at the Tick event the :

Me.Label.Visible = Not Me.Label.Visible

but nothing happened :(

Is the line executed? Did you start the Timer (calling start method or
setting enabled=true)? Do you execute other code while you expect the Timer
to tick? If you do, the Timer won't tick before the code has finished it's
job. To solve it, execute the other code in another thread. This prevents
the main thread that also keeps the Timer ticking, from being blocked by the
other code.


Armin
 
Hi,
Is the line executed? Did you start the Timer (calling start method or
setting enabled=true)? Do you execute other code while you expect the
Timer to tick? If you do, the Timer won't tick before the code has
finished it's job. To solve it, execute the other code in another
thread. This prevents the main thread that also keeps the Timer ticking,
from being blocked by the other code.

also ensure that the value for the timer is not too low (keep in mind
it's milliseconds, so a value of 1000 represents 1 second).

Best regards,

Martin
 
the form2 have a label "please wait" that i want to blink.
at the load event of form1 i have write :

My.Forms.form2.Show()

form2.Refresh()

My.Forms.form2.Timer1.Start()

Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.SKITSA)

My.Forms.parakalw.Close()

but the label at the form2 dont blinking :(
 
giannis said:
the form2 have a label "please wait" that i want to blink. at the
load event of form1 i have write :

My.Forms.form2.Show()

form2.Refresh()

My.Forms.form2.Timer1.Start()

Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.SKITSA)

My.Forms.parakalw.Close()

but the label at the form2 dont blinking :(


See my explanation in my previous post. I also mentioned how to solve it.


Armin
 
Armin said:
See my explanation in my previous post. I also mentioned how to solve it.

At your previous post you say :
"execute the other code in another thread".
What means this ? Sorry but i am a newbie user
of Visual Studio and i dont know very well english...
 
giannis said:
At your previous post you say :
"execute the other code in another thread".
What means this ? Sorry but i am a newbie user
of Visual Studio and i dont know very well english...

I hope these topics are also available in your language in your local help
(<F1>):

http://msdn2.microsoft.com/en-us/library/eed6swsx(VS.71).aspx
http://msdn2.microsoft.com/en-us/library/3e8s7xdd.aspx

In short: A process consists of at least one thread. A thread is a unit that
executes code. Usually you have one main thread. A thread can be a UI (user
interface; showing windows, accepting input) thread. This means that it has
a message loop. The loop is there to process all the messages that are sent
to the windows in the thread. Messages are keyboard or mouse messages, or
timer messages. You handle these message by writing event handlers, for
example the Timer's Tick event handler.

Now, if you press a button and execute the code that you've shown us, the
code does not return to the message loop before the code in the Click
handler has been finished. Consequently, the timer messages are not
processed before you have finished filling the dataset. The label will not
blink.

To solve this, you can create a new thread and do the work in the new
thread. The click event handler immedetially returns to the message loop,
the Timer will tick and the label will blink.

This takes some more work to managed the execution of multiple threads,
but... see the links.


Armin
 
The form2 have the label "please wait" and at the load event of form1 i
write :

Dim t As New System.Threading.Thread(AddressOf mySub)

t.Start()

Call mySub()

Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.TABLE)

Form2.Close()

t.Abort()

where :

Sub mySub()

Form2.Show()

Form2.Refresh()

End Sub

but again the label dont blinking ...

Where is the logical error ?
 
giannis said:
The form2 have the label "please wait" and at the load event of
form1 i write :

Dim t As New System.Threading.Thread(AddressOf mySub)

t.Start()

Call mySub()

Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.TABLE)

Form2.Close()

t.Abort()

where :

Sub mySub()

Form2.Show()

Form2.Refresh()

End Sub

but again the label dont blinking ...

Where is the logical error ?


Multithreading is not really a simple topic. Though... First, the timer must
be started in the same thread that created the window containing the label.
Second, you need a message loop in the thread you started. Call
"Application.Run(Form2)" after showing the form. Otherwise the thread
terminates when the end of the thread's main procedure (sub mysub) is
reached, implicitly destroying the forms created within. Third, you must
close the Form after filling the dataset. Fourth, you must call the Form's
Invoke method to do this because Form's may only be accessed from the thread
that created it.

Armin
 
Armin said:
Though... First, the timer must be started in the same thread that created
the window containing the label.

Sub mySub()
Form2.Show()

Form2.Refresh()

Form2.Timer1.Start()


End Sub
Second, you need a message loop in the thread
you started. Call "Application.Run(Form2)" after showing the form.
Otherwise the thread terminates when the end of the thread's main
procedure (sub mysub) is reached, implicitly destroying the forms
created within.

I receive the error : "Starting a second message loop on a single thread is
not a valid operation. "
when i write :

Sub mySub()

Form2.Show()

Form2.Refresh()

Form2.Timer1.Start()

Application.Run(Form2)

End Sub

What can i write ?

Please can you write some code for me so i understand this important topic ?

Thank you very much for your care !!!
 
giannis said:
The form2 have the label "please wait" and at the load event of
form1 i write :

Dim t As New System.Threading.Thread(AddressOf mySub)

t.Start()

Call mySub()

Omit "Call mySub". t.Start already starts the sub because it's the thread's
main procedure.

You should also create Form2 within mySub.


Armin
 
Armin Zingler thank you very mutch for your helping
understand threads.
Now the blinking label works :

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

Dim t As New System.Threading.Thread(AddressOf mySub)

t.Start()


Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.TABLE)

Form2.Close()

t.Abort()

End Sub

Sub mySub()

Form2.Show()

Form2.Refresh()

Form2.Timer1.Start()

Application.Run(Form2) ' or Application.Run() without the Form2

End Sub
 
giannis said:
Armin Zingler thank you very mutch for your helping
understand threads.
Now the blinking label works :

Glad, I could help. Though, one additional comment:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim t As New System.Threading.Thread(AddressOf mySub)

t.Start()


Me.TABLETableAdapter.Fill(Me.DATABASEDataSet.TABLE)

Form2.Close()

t.Abort()

It's not necessary to call t.abort because the other thread will exit as
soon as mySub has finished. Application.Run automatically exits after Form2
has been closed, but only if you use Form2 as an argument.
End Sub

Sub mySub()

Form2.Show()

Form2.Refresh()

Form2.Timer1.Start()

Application.Run(Form2) ' or Application.Run() without the Form2

End Sub



Armin
 
Back
Top