Notification-area icons for killed processes will disappear if you mouseover them, as this makes Windows check whether the associated process is still running.
Is there a way to trigger this cleanup process programatically?
Is there a way to trigger this cleanup process programatically?
No there is not. I've seen some programs use SendInput to put the cursor over the notification area, but that feels rather dirty to me.
Related
I want to have logic that triggers right before my UWP process is exited or gracefully killed. Is there anything that may accomplish what I wish to do? Or is this impossible in the UWP environment?
I know there exists a trigger for "onSuspending", but I do not want to trigger on that, I want to trigger when the process is exited or gracefully killed. I am aware of the "confirmAppClose" capability and "CloseRequested", but based on research, that seems to only be applicable for the "X" close button. I have a background task with no UI so there is not "X" button visible to trigger it. I am aware of "CoreApplication.Exiting" event but it seems like that won't work either based on what I've read.
I have to say that currently, there is no other ways for UWP to handle the app close request than the CloseRequested event. So it is impossible to get notified when the app is forcibly closed. As you've already known, the CloseRequested event only works when user click the "X" Button.
I have a windows 8 store app and a Background task is also associated with it. Everything working fine. And my question is, is there any possibility to close my app from BackgroundTask Run method ?
thanks for suggestions.
No, You can't do that instantly!
But you could save a file in your app's local storage -or settings- and let the foreground app check for this file every 10 minutes -whatever- and close the app in a specific condition ..
Your background task can be hosted in its own dedicated process or it can be hosted in the same process as your UI. In a separate process your foreground app can open and close without impacting your background process. In the shared process when your foreground app closes, so does the background task. This is not true in reverse, the shared process model does not allow a closing background task to close the foreground app. Too bad, huh?
Technically, it is not recommend that a foreground application close itself. But, hey, that API is there for something, right? When the background task shares the process with the foreground app then it can communicate directly between them with shared memory. This would introduce method 1 for communicating from your background task to your foreground app - probably by using a static event.
If that's not what you want, and you need separate processes, then your options are a bit more tricky.
Here's the best option:
You set a special setting (let's say it's ApplicationData.LocalSettings.Values["DataFromBackground"] = "PleaseExit") and then call the ApplicationData.SignalDataChanged method from the background task which will raise the ApplicationData.DataChanged event handled by the foreground app. How much lag will there be? I am not sure, but there will be some, so be ready for that.
Be sure an remember to set DataFromBackground back to some empty value, including calling Value.Remove() so you don't mistakenly process it again. That being said, you should also poll for that value when your application launches (or resumes) in case your background task wrote it while the event could not be heard.
This is probably the easiest way to implement communication.
Make sense? I speak more on this in my Ignite session on the topic.
Best of luck!
I understand that Chrome using re-parenting in order to have child plugins such as Flash render from different processes.
I have experimented with this, and I have got it working using the SetParent Win32 call.
However, when I force the child GUI thread to block, the parent process will also hang as soon as the mouse moves over a the window area owned by the child process. Presumably this is because the message loop in the parent application is calling down to the child and it never responds. How does Chrome get around this?
Flash uses the re-parenting trick. It has its own .exe and renders to its own window. That doesn't prevent hangs, any message that is sent from that window to its owner is going to block when the owner isn't pumping messages. As you found out.
Browsers uses a different trick. They create an invisible helper process for each tab and render to a memory device context. And blits the result to their desktop window. Any input messages are shuttled back to that process. That makes them immune from crashes and hangs in that process, killing that helper process keeps the browser going. Much harder to do yourself.
I'm trying to make an simple anti-idle script (that moves the mouse or whatever) to prevent an application from stopping.
How can I keep it running after screen lock ?
It seems like this is explained in the Autoit faq :
http://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F
On locked station any window will never be active (active is only dialog with text "Press Ctrl+Alt+Del") In Windows locked state applications runs hidden (behind that visible dialog) and haven't focus and active status.
So generally don't use Send() MouseClick() WinActivate() WinWaitActive() WinActive() etc.
Instead use ControlSend() ControlSetText() ControlClick() WinWait() WinExists() WinMenuSelectItem() etc. This way you may have your script resistive against another active windows. It's possible to run such script from scheduler on locked Windows station.
You can't automate anything after your screen is locked. User input is simply ignored. A much easier way would be to prevent your screen from locking, for example, by moving the mouse randomly every 30 seconds.
I don't really know where to begin. Let's start with the stupid questions:
What language should I use for this? What is suited for the task at hand?
Next, the real ones:
Is there a way to stop the screensaver from starting, short of changing the cursor position? If not, will changing the cursor position even work?
SetThreadExecutionState will prevent the screensaver from coming on or the machine from automatically going to sleep if you pass the ES_CONTINUOUS and ES_DISPLAY_REQUIRED flags.
I wrote an app awhile ago that does exactly what you are asking for. It runs as an icon in the System Tray, not the Taskbar, and uses a global message hook to disable the WM_SYSCOMMAND/SC_SCREENSAVE notification from reaching any applications. If that notification does not reach the DefWindowProc() function, the screen saver will never run.
Your program does not need to be visible in the task bar at all.
You don't even need a program at all, if you can disable the screensaver in the registry.
What you want to do can perhaps be achieved by sending a MOUSE_MOVE event to the desktop window. If you want to use C# (the only language I am current with right now), you can look at this article, but maybe a simple C program using the WinAPI is better suited for this task.
.NET will easily allow you to put an application in the system tray (checkout the NotifyIcon object in System.Windows.Forms.Controls).
I believe you can use the SetCursorPos (http://msdn.microsoft.com/en-us/library/ms648394(VS.85).aspx) API call to prevent the screen saver, just make sure you set them to the current location so you don't actually move the mouse.