Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 876495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:26:28+00:00 2026-05-15T11:26:28+00:00

I am making a program for handheld PDAs using .net 2.0 compact framework and

  • 0

I am making a program for handheld PDAs using .net 2.0 compact framework and I have this one part which I’m not proud of and I was hoping for a more elegant solution.
Basically the problem is another process using my file in this case its Windows Media Player. I start the process by passing the file location to Process.Start but it seems the process returned is short lived and it is spawning another process? So I tried looking up how to get child process information but had some problems with that (i think no processes were being returned for some reason).

So i currently do this dodgy fix

            string processName = item.Text;
            Process proc = Process.Start(processName, null);
            if (!proc.Start())
                MessageBox.Show("Failed to start process", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            else
            {
                IntPtr newWindow = IntPtr.Zero;
                TimeSpan limit = TimeSpan.FromSeconds(3);
                DateTime start = DateTime.Now;
                DateTime now = start;

                // do while the following:
                // window is not null
                // window is not ourself
                // under 3 seconds
                do
                {
                    newWindow = Win32.GetForegroundWindow();
                    now = DateTime.Now;

                    // taking too long
                    if (now - start > limit)
                        break;
                }
                while (newWindow == IntPtr.Zero || newWindow == this.Handle);

                if (newWindow != IntPtr.Zero && newWindow != this.Handle)
                {
                    uint processID = 0;
                    if (Win32.GetWindowThreadProcessId(newWindow, out processID) != 0)
                    {
                        //const int stringSize = 1024;
                        //StringBuilder sb = new StringBuilder(1024);
                        //Win32.GetWindowText(newWindow, sb, stringSize);
                        m_processes.Add(new ProcessIDWithName(processID, processName));
                    }
                }
            }

As you can see I don’t like it and it’s unreliable however it does work for now (i needed a solution whether it was bad or not).
Why do I need the process ID? Because windows media player is keeping the file open on me and I cannot move/delete the file and therefore I need to kill the process off before I do so. I could do a similar fix with FindWindow but I was thinking more generically as it might not be a media file opened in windows media player.

So basically I would like a better solution if possible!

Also if you wondering why I’m not using a Stopwatch its because it doesn’t seem to exist in .net 2.0 cf, also I don’t need accuracy to that extent.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:26:29+00:00Added an answer on May 15, 2026 at 11:26 am

    There are loads of questions that pop up here.

    1. Why aren’t you executing media player itself instead of shellexecuting the name of the target file?
    2. How do you know when the media is done playing in order to close the file?
    3. Why not use the toolhelp APIs to simply enumerate processes instead of the wacky GetForegroundWindow/GetWindowsThreadProcessId shenanigans?
    4. Why aren’t you just using the Media Player ActiveX control instead of this kludge so you’d actually have control over things?

    If you intend to make this generic for any file (i.e. not just media, but maybe something like the Word viewer, etc) then you’re really out of luck and need to rethink whatever it is you’re trying to do (you’ve not told us what you’re trying to achieve, only how you[‘ve decided to implement it). Applications don’t normally close in WinMo, they typically just lose focus of get minimized, so you don’t really know when a user is “done” with the file.

    The application associated with the file may already be running, so terminating it yourself is an unfriendly thing to do.

    The target application really is not designed to give you a callback when it’s done with any particular file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 452k
  • Answers 452k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Turns out, ya just can't do it due to type… May 15, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer This works in the real world because there's single engine… May 15, 2026 at 9:05 pm
  • Editorial Team
    Editorial Team added an answer If you'd like to use Linq To XML, you'd have… May 15, 2026 at 9:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.