Вопрос

I'm trying to see how many instances of an application are running on a MC65 device, a Windows Mobile 6.5 device. Then if there is more than one instance of the application running kill all instances and run the application. I've tried that code here. But it doesn't work on the MC65 device. I believe this is because it is a symbol device and I've read somewhere that they act differently than non-symbol devices.

Does anyone know how to find out what processes are running on a symbol device programatically?

Update: Upon further testing the device is having problems creating a snapshot of the running processes. Still haven't found a solution.

Это было полезно?

Решение

Taking a snapshot should work fine BUT you have to use a flag to avoid memory limitations throwing an exception:

    [Flags]
    private enum SnapshotFlags : uint
    {
        HeapList = 0x00000001,
        Process = 0x00000002,
        Thread = 0x00000004,
        Module = 0x00000008,
        Module32 = 0x00000010,
        Inherit = 0x80000000,
        All = 0x0000001F,
        NoHeaps = 0x40000000
    }

Then in a normal call to CreateToolhelp32Snapshot you can get a list of processes:

    public static Dictionary<UInt32, process> getProcessNameList()
    {
        int iCnt = 0;
        //List<processnames> name_list = new List<processnames>();
        Dictionary<UInt32, process> _pList = new Dictionary<uint, process>();
        uint procID = 0;
        IntPtr pHandle = CreateToolhelp32Snapshot(SnapshotFlags.Process | SnapshotFlags.NoHeaps, procID);
        if ((Int32)pHandle == INVALID_HANDLE_VALUE)
            throw new Exception("CreateToolhelp32Snapshot error: " + Marshal.GetLastWin32Error().ToString());

        if ((int)pHandle != INVALID_HANDLE_VALUE)
        {
            PROCESSENTRY32 pEntry = new PROCESSENTRY32();
            pEntry.dwSize = (uint)Marshal.SizeOf(pEntry);
            if (Process32First(pHandle, ref pEntry) == 1)
            {
                do
                {
                    //name_list.Add(new processnames(pEntry.th32ProcessID, pEntry.szExeFile));
                    _pList[pEntry.th32ProcessID] = new process(pEntry.th32ProcessID, pEntry.szExeFile, new List<thread>());
                    iCnt++;
                } while (Process32Next(pHandle, ref pEntry) == 1);
            }
            else
                System.Diagnostics.Debug.WriteLine("Process32First error: " + Marshal.GetLastWin32Error().ToString());
            CloseToolhelp32Snapshot(pHandle);
        }

        return _pList;
    }

The above code is part of my remote ProcessorUsage test application.

Nevertheless normal windows mobile application will terminate them self if a previous instance is already running. That is also the default when you create and run a SmartDevice project in CSharp or CPP targetting "Windows Mobile ...". If you target a Standard Windows CE based SDK, there is no automatic code generated to prevent multiple instances in the start code of the app.

Let us know, if you still need assistance.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top