Home > Net >  The sleep latency did not achieve the result that want how to return a responsibility
The sleep latency did not achieve the result that want how to return a responsibility

Time:10-09

Seek help from a great god, did not appear on the textbox countdown, how be to return a responsibility?

CodePudding user response:

The form to add a Timer control,

CodePudding user response:

 private System. Windows. Forms. The Timer timer1=null; 
Int I=5;
Public _click ()
{
InitializeComponent ();
Timer1=new System. Windows. Forms. The Timer ();
Timer1. Interval=1000;
This. The timer1. Tick +=new System. EventHandler (enclosing timer1_Tick);
}

Private void button1_Click (object sender, EventArgs e)
{
Timer1. Enabled=true;
Timer1. Start ();
}

Private void timer1_Tick (object sender, EventArgs e)
{
If (I & gt; 0)
{
This. The textBox1. Text=i.T oString ();
i--;
}
The else
{
Timer1. Enabled=false;
Timer1. Stop ();
}
}

CodePudding user response:

Thread.sleep is directly suspend threads, you pause the UI Thread, the system can't update the interface,

CodePudding user response:

After each Sleep plus Applicaiton. DoEvents () to force rendering UI

CodePudding user response:

she would play the soy sauce reference 4 floor response:
add after each Sleep Applicaiton. DoEvents () to make the UI force rendering
so that we can

CodePudding user response:

You can either add a thread, you just pause assignment, not a thread

CodePudding user response:

Private void button1_Click (object sender, EventArgs e)
{

for (int i=0; I & lt; 10; I++)
{
Thread.sleep (1000);
Enclosing textBox1. AppendText (i.T oString ());
}
}
It is OK you try me?
  •  Tags:  
  • C#
  • Related