views:

217

answers:

1

I must port a project to the compact framework. And can not convert to

ThreadPool.RegisterWaitForSingleObject (WaitHandle, WaitOrTimerCallback, object, int, bool)

What may be a alternative way for ThreadPool.RegisterWaitForSingleObject in c#

lock (this.RegLock)
{
    if (!this.WaitFlag)
    {
        this.mre.Reset();
        if (this.handle != null)
        {
            this.handle.Unregister(null);
        }
      this.handle = ThreadPool.RegisterWaitForSingleObject(this.mre, this.WOTcb, null, this.Interval, true);
    }
    else
    {
        this.StartFlag = true;
        if (this.Interval < this.timeout)
        {
            this.timeout = this.Interval;
        }
    }
}
A: 

You can create your own thread and wait for the handle there:

void RegisterWaitForSingleObject(WaitHandle waitHandle, WaitOrTimerCallback callback, object state, int timeout)
{
    var thread = new Thread((ThreadStart)
        delegate()
        {
            if (waitHandle.WaitOne(timeout, false))
            {
                callback(state, false);
            }
        });

    thread.IsBackground = true;
    thread.Start();
}
Shay Erlichmen
waitHandle.WaitOne should be like this in CFif (waitHandle.WaitOne(timeout, bool))
jack london