http://blog.csdn.net/ozhangsan12345/article/details/72653070
First step: Create a Timer object
[HTML]View PlainCopy
- Create a Timer object
- Timer _dispatchertimer;
- Count
- int sec = 60;
Step Two: Instantiate the timer and give the delegate an event
[HTML]View PlainCopy
- TimerCallback timerdelegate = new TimerCallback (Tick);//tick for execution precautions
- _dispatchertimer = New Timer (timerdelegate, NULL, 0, 1000);
Execution method
[HTML]View PlainCopy
- public void Tick (object state)
- {
- This. Runonuithread (() =>
- {
- if (sec > 0)
- {
- SMSBT. Text = sec. ToString () + "Second can be re-sent";
- sec--;
- }
- Else
- {
- _dispatchertimer.dispose ();
- sec = 60;
- SMSBT. Text = "Get Verification Code";
- }
- });
- }
Use
[HTML]View PlainCopy
- {
- TimerCallback timerdelegate = new TimerCallback (Tick);
- _dispatchertimer = new Timer (timerdelegate, NULL, 0, 1000);
- ProgressDialog progressdialog = Progressdialog.show (This, "", "please later ...");
- New Thread (new ThreadStart () =>
- {
- String URL = this . GetString (Resource.String.url) + "/appservices/userservices.aspx? action=regsms ";
- using (var http = new HttpClient ())
- {
- var content = new Formurlencodedcontent (new Dictionary<string, string> () {
- {"Phone", Userphone. Text}
- });
- var response = http. Postasync (URL, content);
- string me = response. Result.Content.ReadAsStringAsync (). Result;
- Progressdialog.dismiss ();
- This. Runonuithread (() =>
- {
- Handleresult (Me);
- });
- }
- })). Start ();
- }
Xamarin.android using a timer and changing the UI