The bundled XPC Service in my macOS application need to do some post processing work with files dumped by the parent app, which most probably can't be completed within the usage time of the application. So, Is there a way to make the XPC service keep running even after the user quits the main app?
You could install it as launch daemon (running in root context as long as computer is switched on) or as launch agent (running in user context as long as user is logged in).
It sounds like you should be using the WatchPaths or QueueDirectories feature of launchd.
WatchPaths starts the job whenever any of the paths being watched have changed
or
QueueDirectories starts your job whenever the given directories are non-empty, and it keeps your job running as long as those directories are not empty
Both of these are covered by Apple's launchd documentation.
Related
I can successfully launch an app with
execl("/usr/bin/open", "open", "/Applications/Foo.app", 0);
But this doesn't work when I'm calling it inside Foo.app
I want my app to relaunch itself when it crashes and autoupdates.
Thanks!
open won't start a second instance of your app if one is already running, it will simply make it the active app.
You can start a second instance of your app by executing the app bundle's executable:
excel("/Applications/Foo.app/Contents/MacOS/Foo", ...
While not the recommended way to launching a Cocoa app, I've been assured by Apple engineers that this will work. But be warned, you now have two instances of your app running, sharing the same NSUserDefaults, and other resources, so expect some strange behavior (or immediately terminate the first app through exit()).
Having said that, this probably isn't want you want to do.
First, you can't "detect a crash and take some action" as—by definition—your app has crashed. There are packages out there that will detect a crash and log information about it; look to a solution like that to restart your app.
As for updates, again I'd steer you towards a third-party solution like Sparkle. It handles quitting your old app, replacing it, and then launching the new one in a sane manner.
Finally, you can register your app as a "user agent" with launchd so that it gets automatically restarted if it quits.
I have a Windows Forms app that is deployed through ClickOnce. In the app, I take advantage of the application settings to store basic connection information. In the two years and 200+ updates since I've published the app and it's been in daily use, I've had no problems with individual users modifying their own settings, and having those settings retained when the application is relaunched and updated.
However, I am working on adding a feature into the app that allows for certain tasks to be scheduled in the Task Scheduler. Everything works fine (the task is scheduled, and the application is called with the correct parameters passed) however when the program is launched, the settings are not read.
I can replicate this by manually launching the application directly from the command line. The application opens, but the only settings available are the settings that shipped with the application initially.
My end question is this: How can I call my ClickOnce app from the command line and have it open the same way as if I'd launched it from the start menu?
Thanks!!
Looks like the answer is to point the Task Scheduler to launch the .appref-ms file that is found in the start menu shortcut. You can't just point to the .exe file.
This is most likely caused by the Command line launching the ClickOnce App under a different user.
Try launching the ClickOnce from Command line or Task scheduler, and loading up task manager and seeing which user the app is running. If it is running on a user other than the user you are logged in as, then you can either log in as the user it is running under (if it's not a system user) and setting what settings you want, or you could try impersonating the desired user through task scheduler.
If none of that is applicable, you could add a Command line switch that, if no settings are found, saves a set of default settings that match what you want.
I have a problem with windows service. I'd like to his level run the program in a given situation. Every minute check a certain value and if the value is to adopt "truth" is to me the program starts. Only at the moment this does not work ...
The problem is that when debugging the code executes correctly, it displays my window, but the service is run normally nothing happens ...
Link to movies about this all:
https://youtu.be/GPv5dn92BGg
You need to jump through several hoops to launch interactive applications from a service. First, the service needs to be explicitly allowed to interact with the desktop. Then the service needs to specify the correct WindowStation for it to show on.
It may be simpler to just set your child application up as a scheduled task, as these can interact with the desktop for you
I am using a Windows Service to run my batch file on scheduled times. The batch file runs an .exe file that is a Console application that simply shows a message and creates a file on a folder. When I run this program manually, the program works and the file is created. But when I try to run the program via my Windows Service the program crashes (or in some cases it asks for permission which is not good).
If I do not use the Console in my program however (nothing shown to the user and everything done in the background), the file is correctly created. I need to make sure that the service runs my .exe/.bat files but it looks like running executable files are a bit risky with services.
Is there a way to solve this problem or should I change my program so that it only does things in the background and does not display anything?
Is your service being run in the LocalSystem account -- the default for all Windows Services? If so, then your console application is being launched in that same account, where it may not be able to find its settings.
Try providing your Windows account on the service's Log On tab to see if that gets around the problems. Be sure to set an account where the console application runs normally!
How do I debug an application which is launched via scheduled tasks?
I have a simple application which works fine when double clicked to launch, but it doesn't work when launched through scheduled tasks.
I know how to debug projects on a local computer, but this application has no issues running on a local computer or on a different computer if launched manually by the user by double clicking the executable file.
I need a way to debug the application when it's being launched by scheduled tasks. Is this possible?
I would primarily suggest putting in some decent logging so that you can diagnose problems without resorting to the debugger. However, to launch the debugger, you can either attach it to an existing process in Visual Studio (using Debug/Attach to process... menu), or change the code to include the Debugger.Launch() method which will launch the debugger and attach it to the process. Of course all of this is dependent on your program actually being executed by the scheduler. If the scheduler doesn't execute the program, then the debugger obviously can't attach to it