Create Timer Task Application In Xamarin.Forms Using Visual Studio

Xamarin Introduction

Xamarin is the best cross platform tool to develop mobile applications. It provides cross platform app development in C#, so we don’t need to write in Java or Objective C. We can just use C# and leverage the same for all the platforms. Xamarin also helps us by providing the designers with the different platforms like Android, iOS, etc.

Working with Xamarin application development, we have two gateways- Xamarin Studio and Visual Studio. Xamarin Studio supports for both Windows or Mac. Visual Studio supports only in Windows, provided you can build and debug on Mac.

Prerequisites

  • Visual Studio 2017 RC.

The following steps are required to follow in order to create Timer Task in Xamarin.Forms in VS 2017.

Timer Task Application

Step 1

Goto the Visual Studio

On File menu>>New>> Project

Click on C#>>Select Android>> Then select Blan App(Android)

Enter the Application Name, Click ok.

Now You can see the Home page of the project.

Step 2

In this step we are going create 3 buttons and Label’s for timer display

Timer Task Application

Timer Task Application

Timer Task Application

Step 3

In this step we going to give the Start button click event and Pause button Click in MainActivity.cs.

Timer Task Application

Timer Task Application

  1. btnStart.Click += delegate {  
  2.     timer = new Timer();  
  3.     timer.Interval = 1; // 1 milliseconds  
  4.     timer.Elapsed += Timer_Elapsed;  
  5.     timer.Start();  
  6. };  
  7. btnPasuse.Click += delegate {  
  8.     timer.Stop();  
  9.     timer = null;  
  10. };  

Step 4

In this step assign the Timer_Elapsed to timer label.

Timer Task Application

Step 5

In this step give Lap button click event.

  1. btnLap.Click += delegate {  
  2.     LayoutInflater inflater = (LayoutInflater) BaseContext.GetSystemService(Context.LayoutInflaterService);  
  3.     View addView = inflater.Inflate(Resource.Layout.row, null);  
  4.     TextView txtContent = addView.FindViewById < TextView > (Resource.Id.textView1);  
  5.     txtContent.Text = txtTimer.Text;  
  6.     container.AddView(addView);  
  7. }; 

Timer Task Application

Step 6

Run the App.

Timer Task Application

Timer Task Application

Timer Task Application

I hope this article is very useful. Thank You.

Up Next
    Ebook Download
    View all
    Learn
    View all