앱이 사용자에게 질문을하는 앱을 개발 중입니다. 예를 들어 사용자가 앱을 평가할 것인지 묻습니다. 이 방법을 실행해야하지만 앱 시작 시간이 크게 늘어납니다. 어떻게 백그라운드에서 실행할 수 있습니까? 별로 도움이되지 않으면 스택 오버플로에 대한 다른 질문을 확인했습니다. 사용백그라운드에서 메소드 실행
:
checkUserStats();
방법 : : 지금이 시도
private void checkUserStats()
{
// Load settings from IsolatedStorage first
try
{
userRemindedOfRating = Convert.ToBoolean(settings["userRemindedOfRating"].ToString());
}
catch (Exception)
{
userRemindedOfRating = false;
}
try
{
wantsAndroidApp = Convert.ToBoolean(settings["wantsAndroidApp"].ToString());
}
catch (Exception)
{
wantsAndroidApp = false;
}
//Check if the user has added more 3 notes, if so - remind the user to rate the app
if (mainListBox.Items.Count.Equals(4))
{
//Now check if the user has been reminded before
if (userRemindedOfRating.Equals(false))
{
//Ask the user if he/she wants to rate the app
var ratePrompt = new MessagePrompt
{
Title = "Hi!",
Message = "I See you've used the app a little now, would u consider doing a review in the store? It helps a lot! Thanks!:)"
};
ratePrompt.IsCancelVisible = true;
ratePrompt.Completed += ratePrompt_Completed;
ratePrompt.Show();
//Save the newly edited settings
try
{
settings.Add("userRemindedOfRating", true);
settings.Save();
}
catch (Exception)
{
}
//Update the in-memory boolean
userRemindedOfRating = true;
}
else if (userRemindedOfRating.Equals(true))
{
// Do nothing
}
}
else
{
}
// Ask the user if he/she would like an android app
if (wantsAndroidApp.Equals(false))
{
// We haven't asked the user yet, ask him/her
var androidPrompt = new MessagePrompt
{
Title = "Question about platforms",
Message = "Hi! I just wondered if you wanted to have this app for android? If so, please just send me a quick email. If enough people wants it, I'll create it:)"
};
androidPrompt.IsCancelVisible = true;
androidPrompt.Completed += androidPrompt_Completed;
androidPrompt.Show();
//Save the newly edited settings
try
{
settings.Add("wantsAndroidApp", true);
settings.Save();
}
catch (Exception)
{
}
//Update the in-memory boolean
wantsAndroidApp = true;
}
else if (wantsAndroidApp.Equals(true))
{
// We have asked the user already, do nothing
}
}
과 같이 단순히 호출
: 필요가있는 방법은 백그라운드에서 실행되는
using System.ComponentModel;
선언 :
BackgroundWorker worker;
초기화 :
worker = new BackgroundWorker();
worker.DoWork+=worker_DoWork;
방법 :하지만이 System.UnauthorizedAccessException 원인
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
checkUserStats();
}
: 내 App.xaml.cs를 잘못된 크로스 스레드 액세스
업데이트 된 질문보기 – Erik
답변에 편집 된 내용 확인 –
그건 내 하루가되었습니다! 감사합니다 Aman! :) – Erik