all groups > dotnet interop > june 2007 >
You're in the

dotnet interop

group:

Process Exit



Re: Process Exit Peter Duniho
6/24/2007 8:25:08 PM
dotnet interop: [quoted text, click to view]

You can always use p/invoke. I'm not aware of a general-purpose mechanism
that allows you to hook window messages the way you can with the native
Win32 API. That said...

[quoted text, click to view]

If you are using the Process class to start the other application, you
should be able to use that Process instance to track the activity of the
other application and detect when it's been closed. You can subscribe to
the Process.Exited event to receive notification of the application
exiting.

[quoted text, click to view]

What did you try? What about it didn't work?

Re: Process Exit Jayme.Pechan
6/24/2007 11:28:50 PM
I have had a problem with a 3rd party out-of-process com object that has a
tendency to crash. Of course, it causes problems when this exe crashes, so
I had to watch to determine when the exe exited. All I did was spin up a
thread that used something simliar to the following:

public void ThreadFunc()
{
Process[] processList =
System.Diagnostics.Process.GetProcessesByName("PROCESS.EXE");
if (processList.length > 0)
{
processList[0].WaitForExit();
// The process has exited
}
else
{
// could not find the process
}
}

Not sure if this is what you are looking for but hope this helps.

Jayme


[quoted text, click to view]
Re: Process Exit jan.loucka NO[at]SPAM gmail.com
6/25/2007 12:00:00 AM
On Jun 25, 11:25 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
[quoted text, click to view]

I'm running the new application by creating a new instance
this.mi = new MapInfo.MapInfoApplicationClass();
my project has a reference to a MapInfo dll - and when I create this
instance it starts the MapInfo app. It's separate process and
therefore I'm expecting it's running on separate thred - on the other
side - my app halts until the loading of MapInfo finishes so maybe
they're both running on the same thread?
I can get the MapInfo process using (I have a pointer - handler to
it):
Int32 pid = win32.GetWindowProcessID(this.miWin.ToInt32());
mapInfoProcess = Process.GetProcessById(pid);
but when I subscribe to Exited event it never gets fired?

I also tried to "subscribe" to the messages coming from MapInfo so I
can catch WM_CLOSE message but I can't get it working.
My code looks like this:
public delegate IntPtr MessageProc(int code, IntPtr wParam, IntPtr
lParam);
IntPtr hookHandle = SetWindowsHookEx(WH_GETMESSAGE,
hookFunction,IntPtr.Zero, AppDomain.GetCurrentThreadId());
public IntPtr NameOfYourFunction(int code, IntPtr wParam, IntPtr
lParam)
{
Message test =
(Message)Marshal.PtrToStructure(lParam,typeof(Message));
return new IntPtr();
}

Process Exit jan.loucka NO[at]SPAM gmail.com
6/25/2007 3:02:10 AM
Hi,
Is there any way in .NET how to capture WIN API messages that belong
to different application? We have a Windows Form app written in .NET
2.0 and from our application we're running another application called
MapInfo using Interop. We need to be able to somehow figure out when
the user exits the MapInfo applicaiton so we can close our own app as
well.
I was looking on SetWindowsHookEx function but couldn't make it work.
Thanks for any help
Jan
AddThis Social Bookmark Button