Xamarin.android using a timer and changing the UI

Source: Internet
Author: User

http://blog.csdn.net/ozhangsan12345/article/details/72653070

First step: Create a Timer object

[HTML]View PlainCopy
    1. Create a Timer object
    2. Timer _dispatchertimer;
    3. Count
    4. int sec = 60;


Step Two: Instantiate the timer and give the delegate an event

[HTML]View PlainCopy
    1. TimerCallback timerdelegate = new TimerCallback (Tick);//tick for execution precautions
    2. _dispatchertimer = New Timer (timerdelegate, NULL, 0, 1000);

Execution method

[HTML]View PlainCopy
  1. public void Tick (object state)
  2. {
  3. This. Runonuithread (() =>
  4. {
  5. if (sec > 0)
  6. {
  7. SMSBT. Text = sec.   ToString () + "Second can be re-sent";
  8. sec--;
  9. }
  10. Else
  11. {
  12. _dispatchertimer.dispose ();
  13. sec = 60;
  14. SMSBT.   Text = "Get Verification Code";
  15. }
  16. });
  17. }

Use

[HTML]View PlainCopy
    1. {
    2. TimerCallback timerdelegate = new TimerCallback (Tick);
    3. _dispatchertimer = new Timer (timerdelegate, NULL, 0, 1000);
    4. ProgressDialog progressdialog = Progressdialog.show (This, "", "please later ...");
    5. New Thread (new ThreadStart () =>
    6. {
    7. String URL = this . GetString (Resource.String.url) + "/appservices/userservices.aspx?  action=regsms ";
    8. using (var http = new HttpClient ())
    9. {
    10. var content = new Formurlencodedcontent (new Dictionary<string, string> () {
    11. {"Phone", Userphone. Text}
    12. });
    13. var response = http.  Postasync (URL, content);
    14. string me = response. Result.Content.ReadAsStringAsync ().  Result;
    15. Progressdialog.dismiss ();
    16. This. Runonuithread (() =>
    17. {
    18. Handleresult (Me);
    19. });
    20. }
    21. })). Start ();
    22. }

Xamarin.android using a timer and changing the UI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.