Xamarin Public Jenkins f3e3aab35a Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
2016-02-22 11:00:01 -05:00

53 lines
1.7 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Threading.Tasks.Dataflow.Internal.Threading
{
internal delegate void TimerCallback(object state);
internal sealed class Timer : CancellationTokenSource, IDisposable
{
internal Timer(TimerCallback callback, object state, int dueTime, int period)
{
Debug.Assert(period == -1, "This stub implementation only supports dueTime.");
Task.Delay(dueTime, Token).ContinueWith((t, s) =>
{
var tuple = (Tuple<TimerCallback, object>)s;
tuple.Item1(tuple.Item2);
}, Tuple.Create(callback, state), CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Default);
}
public new void Dispose() { base.Cancel(); }
}
internal sealed class Thread
{
internal static bool Yield() { return true; }
}
internal delegate void WaitCallback(object state);
internal sealed class ThreadPool
{
private static readonly SynchronizationContext _ctx = new SynchronizationContext();
internal static void QueueUserWorkItem(WaitCallback callback, object state)
{
_ctx.Post(s =>
{
var tuple = (Tuple<WaitCallback, object>)s;
tuple.Item1(tuple.Item2);
}, Tuple.Create(callback, state));
}
}
}