CeSetThreadPriority, Handle IntPtr

  • Hallo


    Wie bekommt man unter C# für eine importierte CeSetThreadPriority Methode an den benötigten IntPtr für den Thread Handle ?


    [DllImport("coredll.dll", EntryPoint = "CeSetThreadPriority", SetLastError = true)]

    public static extern bool CeSetThreadPriority(IntPtr hThread, int nPriority);


    Möchte für einen Thread die Priorität auf 150 erhöhen.


    Danke.

  • Hello,


    it is the same under WCE6 and is in the coredll.dll. It is often used by the WCE modules!

    Any mistakes in your code?

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • Hello, found following magic code from opennetcf seem to work:


    using System;

    using System.Linq;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using System.Runtime.InteropServices;

    namespace CeSetThreadPriority

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    IntPtr p = GetCurrentThread();

    Int32 i32 = CeGetThreadPriority(p);

    label1.Text = i32.ToString();

    }

    private const int SH_CURTHREAD = 1;

    private const int SH_CURPROC = 2;

    private const uint SYSHANDLE_OFFSET = 0x004;

    private const int SYS_HANDLE_BASE = 64;

    public static IntPtr GetCurrentThread()

    {

    return new IntPtr(SH_CURTHREAD + SYS_HANDLE_BASE);

    }

    [DllImport("coredll.dll", EntryPoint = "CeGetThreadPriority", SetLastError = true)]

    public extern static Int32 CeGetThreadPriority(IntPtr hHandle);

    [DllImport("coredll.dll", EntryPoint="CeSetThreadPriority", SetLastError = true)]

    public static extern bool CeSetThreadPriority(IntPtr hThread, int nPriority);

    int i = 0;

    private void button1_Click(object sender, EventArgs e)

    {

    IntPtr p = GetCurrentThread();

    CeSetThreadPriority(p, 123+(i++));

    Int32 i32 = CeGetThreadPriority(p);

    label1.Text = i32.ToString();

    }

    }

    }

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.