Re: Timer not working in thread
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 4 Apr 2008 14:15:58 +0100
<sony.m.2007@xxxxxxxxxxxxxx> wrote:
Hi,
My application processes a file and updates the data into sql server.
The process takes around 30-90 seconds.I decided to put a timer to
display the user a label(making label visible false and true) with
message like "processing..." and do the other process using thread.
The timer won't works when the thread is started, so the label is not
displayed in the form
I have a label label1,a timer timer1 and command button in a form
timer1.interval=100;
private void timer1_Tick(object sender, System.EventArgs e)
{
label1.Visible = ! label1.Visible;
}
private void commandButton_Click(object sender, System.EventArgs e)
{
timer1.enabled=true;
label1.visible=true;
this.refresh
Thread t=new thread(new threadstart(updateMethod))
t.start()
timer1.enabled=false;
label1.visible=false
}
When I execute the above code label is not displayed in the
form.After the completion of thread only label get displayed.
Is there anything wrong in the above method of blinking a label?
In the above code (which clearly isn't your *real* code, btw, due to
the casing - it's always worth posting genuine code) you've started the
thread and then *immediately* stopped the timer and made the label
invisible. Why? Surely UpdateMethod should do that when it finishes.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.
- Follow-Ups:
- Re: Timer not working in thread
- From: sony . m . 2007
- Re: Timer not working in thread
- References:
- Timer not working in thread
- From: sony . m . 2007
- Timer not working in thread
- Prev by Date: Timer not working in thread
- Next by Date: Re: Timer not working in thread
- Previous by thread: Timer not working in thread
- Next by thread: Re: Timer not working in thread
- Index(es):
Relevant Pages
|