I am having yet another problem with my application for my phone.
My problem is the following:
On one page I have a list of pictures, and a button marked as "favorite." If you are to favorite the particular image of the row, the border of the image changes colors to signify this.
However, whenever I tombstone my application or hit the back button and go back to that very same page, the borders of the images are back to their default color.
Now before you ask, I have no idea if this is an isolated memory problem. I have just begun looking into Isolated storage, and it's difficult for me to grasp at the moment.
Maybe this is a saving state problem?
Either way, I would like to have my application remember what the favorites are whenever a user exits the application or tombstones it, or hits the back button, etc.
Could someone please provide a piece of code in order to help with this?
You need to save your data because the system is basically killing your app. So you need in your app.xaml.cs write code to save and read your data in metods:
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}
Related
I'm developing program perform multiple tasks in the loop, use 3rd party libraries. But when it's done a job, it automatically appears in front of screen, made me lose focus. How to disable auto appear? I've tried:
private void FrmMain_Activated(object sender, EventArgs e)
{
SendToBack();
}
But it was only after the program appear, bring it back to the rear. I want to prevent it bring to front from the firt. Please help me!
I have created a simple C# application to automatically login into a hotspot. I have a notify icon with a contextmenustrip with some functions like Connect, Disconnect, etc. I want to be able to run the form in the background showing only the notify icon to automatically login into the hotspot if the form is hidden.
I followed the instructions from VBNight in this post:
Hide form at launch
The application is running in the background, the notify icon showing but the Form_Load function is not working until I press on the notify icon.
I guess that's because Form_Load Occurs before a form is DISPLAYED for the first time.
Try moving your code from Form_Load to the constructor after InitializeComponent(); or so.
EDIT:
To answer your question, I suggest you extract code #1 from...
private void YOUR_BUTTON_Click(object sender, EventArgs e) {
// move this code #1 to...
}
and move the code to a brandnew method.
private void NewButtonClicked() {
// move code #1 here (in case)
}
Then, go back and call the method you just created.
private void YOUR_BUTTON_Click(object sender, EventArgs e) {
// You can leave code #1 but to remove duplicate,
NewButtonClicked();
}
Finally, replace YOUR_BUTTON.PerformClick(); with NewButtonClicked(); wherever you need. I assume you don't need any interaction with form Controls since the form is hidden.
I fixed it changing the form opacity to 0 and the ShowInTaskbar property to false. The form is hidden and the code is working.
I have an ASP.NET application in which I have a function that runs on a button click event, all I need is to have another button which when clicked the function that is running should stop executing. I have added the sample code. Can someone please help me on this? Thanks
protected void btnCreateSites_Click(object sender, EventArgs e)
{
GenerateSites("CPM");
}
static void GenerateSites(string siteName)
{
//perform some complex operation here
}
protected void btnStopExecute_Click(object sender, EventArgs e)
{
//stop the execution of the GenerateSites() function when this button is clicked.
}
The first click event needs to launch a separate thread to run the process and store the reference to that thread somewhere. The second click event will get the reference of that thread, if it still exists, and call abort.
That's the simple way. Add some code to your question for an answer that is better suited to what you are trying to achieve.
Tell me please how to execute a method BackgroundAudioPlayer fastforward?
That is, how to do that when you long press the button, fast forward, and then release the button, the track nchinal play, in general as well as buttons work in the locked mode.
If you long press call as follows:
private void btnNext_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
BackgroundAudioPlayer.Instance.FastForward();
}
The track is scrolled to the end and pops up an error.
What is your desired behavior? You probably need some code on the MouseLeftButtonUp event to call Play to resume the playing of the current audio track.
I'm experiencing odd behavior in the wp7 emulator.
I have a dead simple app that's mostly directly from the template generated by VS 2010.
From App.xaml:
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
Tombstoning code from App.xaml.cs:
private void LoadSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
ICollection<TicTacSpot> getSpots;
if (settings.TryGetValue<ICollection<TicTacSpot>>("spots", out getSpots))
{
Spots = getSpots;
}
if (Spots == null)
{
Spots = new List<TicTacSpot>();
}
}
private void SaveSettings()
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["spots"] = Spots;
}
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadSettings();
}
// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
LoadSettings();
}
// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
SaveSettings();
}
// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
SaveSettings();
}
Seems straightforward enough. I set breakpoints in all these methods. When I hit F5 to deploy the app, the event handlers that are hit are:
Application_Launching()
Application_Deactivated()
Oddly, these are hit, even though the emulator doesn't show the app opening or closing.
In the emulator, I then open the app, play around, close it, then re-open it. I use both the "back" and "start" buttons to close it. Despite this, I am unable to get any event handlers to be hit again.
What am I doing wrong here?
Is the debug session is still active?
I have found that if you set breakpoints that get hit on start-up and you do not continue with a certain amount of time (e.g. < 10 seconds) your debug session will be disconnected.as the OS terminates the application.
Like Dennis said, to debug the Activated event handler you need to launch a new debug session just after pressing the back button. The sequence would be :
launch debug
play with the app, hit Start
quit application, debug session stopped
hit back button - black screen on the emulator
launch debug session , be quick :) after 10 sec, OS terminates the application