YogI YogI - 1 year ago 129
C# Question

Pass Parameter or Arguments to a Background task in Uwp

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.

Answer Source

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

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

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

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

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

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download