Re: Timer not working in thread

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



<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
.



Relevant Pages

  • Re: Timer not working in thread
    ... display the user a labelwith ... The timer won't works when the thread is started, so the label is not ... Surely UpdateMethod should do that when it finishes. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: how to re-draw controls on a Form at a regular interval?
    ... passively -- but I need an auto-refresh approach. ... and in this Form I want to display the updated ... then you can use a timer as I suggested earlier. ... simply update the Text property of the label, ...
    (microsoft.public.dotnet.languages.csharp)
  • Timer not working in thread
    ... display the user a labelwith ... The timer won't works when the thread is started, so the label is not ... private void commandButton_Click(object sender, System.EventArgs e) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simpel TextBox Question
    ... display a couple of seconds apart. ... You need to separate your updates so that the message pump gets to run between updates. ... There are a variety of ways to approach the problem, but assuming you can tolerate a timing precision of around 50ms, I'd recommend using a Timer object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mail Counter in asp.net 3.5
    ... that can get the updates. ... to put a counter on a page to display sent mails like 12/123. ... to display the counter value is label but in vain. ... Sajit Nayar. ...
    (microsoft.public.dotnet.framework.aspnet)