標籤:users log urlencode var detail ssd clip using views
http://blog.csdn.net/ozhangsan12345/article/details/72653070
第一步:建立timer對象
[html] view plain copy
- //建立timer對象
- Timer _dispatcherTimer;
- //計數
- int sec = 60;
第二步: 執行個體化timer並給委託事件
[html] view plain copy
- TimerCallback timerDelegate = new TimerCallback(Tick); //tick為執行防範
- _dispatcherTimer = new Timer(timerDelegate, null, 0, 1000);
//執行方法
[html] view plain copy
- public void Tick(object state)
- {
- this.RunOnUiThread(() =>
- {
- if (sec > 0)
- {
- smsbt.Text = sec.ToString() + "秒可重發";
- sec--;
- }
- else
- {
- _dispatcherTimer.Dispose();
- sec = 60;
- smsbt.Text = "擷取驗證碼";
-
- }
- });
-
- }
//使用
[html] view plain copy
- {
- TimerCallback timerDelegate = new TimerCallback(Tick);
- _dispatcherTimer = new Timer(timerDelegate, null, 0, 1000);
- ProgressDialog progressDialog = ProgressDialog.Show(this, "", "請稍後...");
- 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 使用Timer 並更改UI