This project has moved. For the latest updates, please go here.

ProcessId

Jul 28, 2015 at 3:59 PM
When i create a new MSProjectApplication I can see that a new WInProj.Exe process starts, How can I obtain the PID of this process? I need It 'cause i would like to be able to kill that process

My Office application run in background.
Coordinator
Jul 29, 2015 at 8:15 PM
I can show how you enumerate all MSProject main windows(from the desktop with some NetOffice utils classes) and get the associated PID('s) from them.
But this is a wrong way of course. (a well known anti-pattern.. the abort hammer)

Do you have problems because MSProject is not going down after quit/exit?
NetOffice spend a lot of help here to make sure you dont leave the place with open (COM)references. (just 1 call more...)

let me know...and choose

1:) i want kill !!! no matters for your blabla...
2) how i can make this better


*Sebastian
Jul 30, 2015 at 9:11 AM
The problem I need to solve is this one, :
I have a WCF service that operate with MSProject, MSProject is STA and I need to operate in an MTA context, with multiple instances of MSProject that might work at the sime time in response of the simoultaneus client requests, for solve this I have created a pool of users that instance the MSproject, when I receive a request i serach for an user that is free and call a thread impersonated with the user tha open the MSProject app and work with this. so I can have more instances of the MSProject that can work at the same time.
I would like to manage a list that report the User that have actualy instanciated the MSProject, the MSProject Instances reference and a timestamp that reeport when the MSProject was Instanciated
If there are no problems the MSProject app is closed and the thread released and the user return free (release the user from the List).
If there are problems, sometimes MSProject app hangs and I need to manually kill the process but If I'Ve more instances at the same time I'm not able to kill it in a secure way, for avoiding this If I can associate the user with the process Id of the MS Project when pass 10 minutes form the timestamp i can decide that the MSProject is hanging and so kill them by code and release the user from the list.
In my context MSProject work in a background way without open Windows.
Can you help me to solve this problem?
Coordinator
Jul 31, 2015 at 5:08 PM
hello,

the first what i have to say is about multi-application scenarios.
its more safe/isolated to create an own NetOffice core for each application.
(NetOffice.Core manage all open com proxies, make sure to dispose the root object i.e application to cleanup your environment)
MSProject has also problems sometimes with the automation api (RPC_REJECTED_EXCEPTION)
a good way is to use something like this.
    public static MSProject.Application CreateApplication()
    {
        NetOffice.Core core = new NetOffice.Core();
        core.Settings.MessageFilter.Enabled = true; // MSProject has known issues without
        // core.ProxyCount <= watch the current open proxies always a bit. more than 1000 is very exceptional

        // NetOffice doesnt spend the right ctor to give an own core if application is created at hand.
        // we fool the application a bit and create an application instance with ouer own core. 
        // (default core is always NetOffice.Core.Default)
        MSProject.Application application = new MSProject.Application();
        application = new MSProject.Application(core, null, application.UnderlyingObject);
        return application; // make sure to call dispose after quit 
    }
For the PID its good to use the Win Api here.
  [DllImport("user32.dll", SetLastError = true)]
  static extern int GetWindowThreadProcessId(int hWnd, out int processId);
But unfourtently, MSProject doesnt have an accessible main window handle. for this reason use a bypass trick:
 int pid = 0;
 GetWindowThreadProcessId(application.VBE.MainWindow.HWnd, out pid);
This sample use the integrated VBA window instead. Works fine and no security hurdles for the readonly access.


*Sebastian