views:

233

answers:

4

I want to create a Mono application to start and stop several processes. I only need to be able to start and stop the processes from the Mono application, I do not need any advanced features of managed processes. Users will be able to customize the available processes from a "preferences" menu.

The problem is, that I also need to be able to create a IdleHandler, but the handler will not fire, because the application is never able, due to the processes, and the GUI (GTK#) becomes unresponsive due to the weight of the processes. Is there a way to start and stop completely unmanaged processes from Mono?

Lowering the priority of the processes is not possible, because this will lead to audio dropouts.

Here is a basic description of the application that I try to make: http://ix.residuum.org/monomultijack.html

A: 

Edit: the basic problem seems to be that you're waiting for an Idle even to be raised when the machine is not idle. The documentation says:

Another use of the Idle handler is to queue work to be done when the machine is idling and not doing anything interesting.

It doesn't explicitly say what happens when your application is idle and another application is using the CPU, but the sentence above makes it sound like the handler might not fire unless the entire machine is idle, not just your application. So the behaviour you're seeing may well be by design.

Original answer:

I'm not quite sure what your question is. What's the basic problem you're trying to solve?

If the problem is that the process takes up all CPU you could give it a lower priority:_jackd.PriorityClass = ProcessPriorityClass.BelowNormal

If you improve the question I may be able to improve the answer. :)

Evgeny
Unfortunately, lowering the process's priority is not an option, as the process should run with a high priority.
Residuum
I still don't understand the problem. What is it that you want your code to do that it currently doesn't do?
Evgeny
+1  A: 

Could you not just trigger the init.d script that starts jackd? (Just assuming that there is an init.d script since we're talking about a daemon)

If there isn't such a script, could you not make one? The daemon launches itself in the background, so the process you would be starting is the bash-process that runs the script, which then exits when the daemon is launched in the background.

Stopping would work the same way.

Christian W
I ended up writing bash scripts to /tmp/ with System.IO.Path.GetTempFileName() and returning the process id. Then for stopping the processes I just start a new process with kill $pid.
Residuum
A: 

Your question doesn't make a whole lot of sense. If you want to start another process and then kill it when the user clicks a button, you would simply create your process and run it:

private Process _jackd;

public void StartJackd() 
{ 
    _jackd = new Process (); 
    _jackd.StartInfo = _jackdStartup; 
    _jackd.Start (); // Non-blocking
} 

Then if you want to stop it:

_jackd.CloseMainWindow();

or

_jackd.Kill();

If your application is a bit slow to terminate it, then you could raise the priority of your application to High as well.

If this isn't what you're looking for, I would suggest explaining in more detail what you're trying to do.

SLC
A: 

I am trying to guess as to the exact meaning of your question.

Are you saying that you have a group of process which you are starting in the application, some of which are idelhandlers(ie process which you fire when the app is doing nothing) and the idlehandlers never get fired because the other processes are always running?

My understanding of the idle Handler is that it will only ever get fired when the gtk application loop has no more events to process. If you are launching other system process (ie jackd) it should not be effecting the main application loop (as these processes are running on a system level not in the application).

Is it possible that you have any method in the main application which would be constantly firing? (such as an event listener which fires every second)

If so would it be possible to abstract those events out into a separate process, and then only then notify the main application when an update needs to be made? This should then allow the idel handlers to be fired.

Another possible solution is could you use timeout methods instead of idlehandlers. If there are functions which you need to fire frequenetly(say every 10ms or so) then a timeout handler may be a better fit anyways.

Sadly without more information on exactly what processes you are running and what you are trying to process with the idlehandlers it may be hard to give you an exact answer.

Didius