将参数或参数传递给 Uwp 中的后台任务 [英] Pass Parameter or Arguments to a Background task in Uwp

查看:28
本文介绍了将参数或参数传递给 Uwp 中的后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 uwp 应用程序,我想在其中从用户说的文本框中获取一些数据,然后将其传递给后台任务.但是,当我尝试向后台任务添加项目引用时,出现循环引用错误.那么有什么方法可以传递参数,可能是 run 函数的重载或其他任何东西.提前致谢.

I am creating a uwp app in which I want to take some data from user say from a textbox and then pass it to a background task. But when I am trying to add project reference to the background task I am getting a circular reference error. So is there any way to pass arguments maybe a overload of run function or anything else. Thanks in advance.

推荐答案

Romasz 已经完美地解释了它,但在您的情况下,您可以通过执行以下步骤从文本框中获取用户数据:

Romasz has explained it perfectly but in your case you can get the user data from the textbox by doing these steps:

1.在 MainPage.xaml.cs(或您的 xaml 页面)中声明此内容

1.Declare this in MainPage.xaml.cs(or your xaml page)

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["user"] = User.Text;

2.现在使用这些获取BackgroundTask.cs中的数据

2.Now get the data in BackgroundTask.cs using these

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
string user = localSettings.Values["user"].ToString();

这里的变量 user 有你想要的主页的 texbox 数据.

Here the variable user has the texbox data you wanted from the mainpage.

注意:我假设您已将文本框命名为用户"

Note:I have assumed that you have named your textbox "User"

这篇关于将参数或参数传递给 Uwp 中的后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆