locked
How to share a class between a background task and main App? RRS feed

  • Question

  • My main App has a Class1.cs which I want to re-use in my timer background task. The background task itself trigs as as expected every 15 min, but the compiler fails when I do "Add-As-Link" on Class1.cs into the background task project. Obviously the background task class is already referenced in the main App and there seems to be a compiler conflict in App..

    How can I get around this ? 

    Monday, February 3, 2014 1:14 PM

All replies

  • have a look how i did it in this project:

    http://code.msdn.microsoft.com/windowsapps/Tile-Update-every-minute-68dbbbff

    i putted the work of the background task in a own class. that class i also using in the app


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, February 3, 2014 1:17 PM
  • Thanks, I upgraded your solution to target Windows 8.1 and ran it.

    But I am not sure I understand... I can't see any class being shared between the App and the background task in any direction..?

      
    • Edited by Southbranch Monday, February 3, 2014 3:28 PM
    Monday, February 3, 2014 3:28 PM
  • check the ClockTileScheduler class. it used in the application and in the background task

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, February 3, 2014 8:39 PM
  • Sorry, you are right. It is shared from the background task to the main app

    Problem is I want to share my class the other way around... How can I do this?

    Monday, February 3, 2014 9:30 PM
  • I can't get it to work with sharing code using "Add-As-Link".. But it seems possible using a Portable Class Library (DLL), maybe is this  the only way?
    Monday, February 3, 2014 9:46 PM
  • well .. that possible too .. but why want to share in different way. what kind of problem you try to solve?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, February 3, 2014 9:55 PM
  • The main App hosts class logic in order retrieve items from a server API. When the app is in the ordinary foreground mode it uses this logic. However, when the app is suspended I want a background task to share the same code in order to call the server every 15 minutes and update the tile if any new items arrives at the server end.

    I gues you can compared it with updating the tile with new "Facebook status".

    Monday, February 3, 2014 10:05 PM