Background Service for iOS in C#

Hello Everyone,

I am writing app for multi-platform like Android and iOS.

I referred to http://docs.xamarin.com/recipes/android/fundamentals/service/create_a_simple_service for writing my background service for Android.

Now, I have requirement of the same to write in iOS. I am not getting appropriate link to refer. I have taken a look at below Thread too.

http://forums.xamarin.com/discussion/1286/background-services-in-monotouch

Please point some references or post the code to the Thread if anyone have encounter this earlier and found a fix.
Kindly help me in achieving this...

Thanks
Deepak

Posts

  • Maico2007Maico2007 MXMember ✭✭

    you can use a BackgroundWorker, this is similar

    //Library
    using System.ComponentModel;
    
    //Global variable
    public BackgroundWorker trabajador = new BackgroundWorker();
    
    //Activate  BackgroundWorker
    this.trabajador.RunWorkerAsync();
    
    
    //When activate
    public void trabajador_DoWork (object sender, System.ComponentModel.DoWorkEventArgs e)
    {
          //Your Code is Here
    }
    
    //when finished
    public void trabajador_RunWorkerCompleted (object sender, System.ComponentModel.RunWorkerCompletedEventArgs e1)
    {
          //Final Code
    }       
    
  • DeepakRameshDeepakRamesh USMember
    edited July 2013

    Thanks for your kind reply Adrian.

    I have resolved my issue in following manner.

    I have put this lines of code in ViewDidLoad() override method

    NSTimer.CreateRepeatingScheduledTimer (1, delegate {
         runInBackground ();
        });
    

    And my runInBackground method is here

    private void runInBackground()
    {
          //My Logic to run in background.
    }
    

    Thanks
    Deepak

  • anji22anji22 USMember ✭✭

    @DeepakRamesh said:
    Thanks for your kind reply Adrian.

    I have resolved my issue in following manner.

    I have put this lines of code in ViewDidLoad() override method

    NSTimer.CreateRepeatingScheduledTimer (1, delegate {
         runInBackground ();
        });
    

    And my runInBackground method is here

    private void runInBackground()
    {
          //My Logic to run in background.
    }
    

    Thanks
    Deepak

    will It work when app killed?

Sign In or Register to comment.