后台任务UWP - 使用数据传递对象

时间:2016-04-01 11:13:40

标签: object win-universal-app windows-10 isolatedstorage background-task

我需要在后台任务中传递一个包含一些信息的对象。我尝试在网上搜索但没有找到任何解决方案。有可能吗?

一个workarround是保存信息,我需要在MainProjet中的隔离存储中传递,并在我的BackgroundTask项目中使用以前保存的信息。但是这个解决方案并不美观。

有人帮助我吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以使用SendMessageToBackground方法

    double tuition = 10000;
    double count = 1;
    double percentageIncrease = 1.05;
    double increasedTuition;
    double sumOfTuitionAfterFourYears = 0;
    double increasedTuitionTwo;

    do {
        //This is the correct incremental formular
        tuition = tuition * percentageIncrease;
        //increasedTuition = increasedTuition * percentageIncrease;
        count++;

        //Formatting the number of digits after the decimal point
        increasedTuition = (int)(tuition * 100) / 100.0;

        //This if statement must be inside the loop body
        if (count > 10) //Note, do not put a semi-colon here
        System.out.println("Tuition in ten years is " + increasedTuition);

    } while (count <= 10); //End of first loop

    do {
        increasedTuition = increasedTuition * percentageIncrease;

            //Formatting the number of digits after the decimal point
            increasedTuitionTwo = (int)(increasedTuition * 100) / 100.0;

            //Adding the result above on each iteration pass
            sumOfTuitionAfterFourYears += increasedTuitionTwo;

            if (count == 14) 
            System.out.println("The sum of four years tuition starting from 10 years is " + sumOfTuitionAfterFourYears);

        //Increments the count from 10 since our base tuition is the last tuition in the last loop
        //You can also write your continuation-condition like this: (count >= 10 && count <= 14). 
        //You will get the same result without changing the base tuition
        count++; 

    } while (count <= 14); //End of second loop

在后台任务中听这个方法

  var message = new ValueSet();
                    message.Add("key",value);
                    BackgroundMediaPlayer.SendMessageToBackground(message);