tags:

views:

65

answers:

3

Hi, i want to know how i can start my c# program when another application is launched. I want only this application to start my program beacuse i will be doing some processing of the output from the application. The app was installed not written by me. I don't want to write a service.

A: 

Process.Start is what you are looking for

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(VS.71).aspx

Pierre 303
If the OP doesn't control the source of the app that should cause his application to start how is Process.Start going to help him?
Wil P
Thanks Wil P, that is exactly the case....please help me with a correct answer.
ManX
He can write a small window less application that will use Process.Start to launch his application if the other application is launched. If he don't want to write a service he can put a task in task manager. If he can't control the other application, his choices are limited
Pierre 303
+1  A: 

You may be able to use WMI in a second application that you create as seen here to monitor for the process you're looking for and then have your second 'monitor app' that is always running (not necessarily as a service) fire up your application to process the output of the application you want to have cause your app to run.

Other things we've done is have our app run from user login by adding it to the start up folder or by calling it from a scheduled task to look for data to process. Not sure what works for ya, but maybe some options you can make use of.

EDIT: @ManX IMO the monitor method works really well and I see no real problems processing thousands of reports per day in my apps using this method. I just look for new 'output' data, reports in your case in particular locations and process them accordingly. Typically our apps run in windowless mode, only being brought into the foreground whenever the user needs to interact. In your case this would be when a new report has been created. There are many facilities in the .NET framework that would allow you to write a flexible lightweight monitoring application.

Find one of the timers that suits you and periodically check for new reports. It will be an almost immediate reaction to the report creation and should be seamless for the user.

EDIT #2.

Look at creating a Permanent WMI event consumer... Then you can just use Process.Start to fire up your app as others have recommended whenever you detect an event that you care about.

Wil P
I am trying to avoid monitoring that's why i shunned writing a service. I was hoping for a way to trigger my app from the other app. i may be wrong but a monitoring WMI has little or no advantage over a service...please advice.
ManX
Since I have had need of similar functionality in past time, I've given this a lot of thought long time ago, and whereas your ambition to avoid a service may be an admirable one, I think you're out of options. It is either going to be a service, or a process launched as part of the start-up, both of which use WMI. I've never solved my own problem, so I can't advise, but I think that @Wil P's links should get you moving in the right direction.
Cyberherbalist
A: 

It looks like you want the launching of some outside app trigger the launching of your own app.

If you can control when the outside app starts, then you can make your own app start at the same time. What amounts to downright low-tech tech, for example, if that outside app can be launched using a batch file, simply include your app in the batch, e.g.

echo off
start OutsideApp.exe
MyOwnApp.exe

The command "start" fires off OutsideApp.exe and lets it run while executing the next instruction in the batch, MyOwnApp.exe.

But @WilP's response may be more what you're looking for. If it fits, though, mine is quicker to implement. :-)

Cyberherbalist
I thought of a batch script too but it seemed way to simple to implement. OP, what kind of output are you processing from the 'outsideapp.exe'?
Wil P
yes i wish to trigger my app from the other app. Users of the other app are the only ones with control and my app is to start processing for each user.
ManX
The outsideapp.exe will process reports for each user in real-time
ManX
Can you add a scheduled task via your installer that causes your application to run periodically looking for output to process instead of having being started by the other app? App runs every so often looking for data, processes it if there is any and then exits?
Wil P
No, i really do not want my app or another to monitor....i prefer the OS to monitor(perhaps through scheduled tasks or some other way) but only iff the immediate trigerring is impossible
ManX
and when i say the OS should monitor i only want it to monitor the launching of the other app or a particular thread in it....yet, like i said only if immediate triggering is impossible
ManX
there is a synchronization issue involved that is why it cannot monitor data
ManX
See my answer i provided a comment there instead.
Wil P
What is the synchronization issue? If it is to do with the fact that the other process still has handles to the data, this can be dealt with using a cache of references to the file paths. Your application will only be invoked when new files (I'm assuming reports are in the files system) are of a certain age and the are no handles on the data it needs.
Wil P
the real-time is very important for the processing to be done correctly...there are mapping and matching issues...my app has to catch things done by the other app...this portion has already being written successfully i just need to integrate it by starting my app at the correct time
ManX
i have done a test run of starting the other app followed by my app and things have been great...now i need to automate the launchings
ManX
i mean automate just my app launching as the other app will always be launched manually
ManX
If that is the case then why can't you have your app run all the time and only be brought into the foreground whenever the time is right? You could then actively use WMI to monitor external process creation, periodically poll directories / data stores for new data, or setup a FileSystemWatcher and carefully respond to it's events whenever new data is made available. Too bad the application you are integrating with doesn't have any hooks that allow you to more seamlessly integrate with it and respond accordingly to events you care about.
Wil P
Checkout the link re permanent wmi event consumers. They don't require you to have an application running all the time. So you can use WMI and the permanent event consumer to respond to the particular event you care about and you can react to it as you desire. Good Luck!
Wil P
okay it seems the triggerring is impossible although i was hoping for pointers on writing a dll that could be placed in the other app's directory and loading it when the other app was launched...this dll would have code that starts my app...do you know if this can be done and how?....Let's talk a little about the WMI...can it monitor the system for a particular process or thread (from the other app) and fire off my own when it sees one?
ManX
thanks for your comments and answers
ManX
@ManX No problem. I think the short answer is yes it should be able to do that. The WMI classes are easy to work with. Hopefully some of the info here is helpful. I'm out for the day. Look forward to hearing you were able to solve your problem.
Wil P