public static Timer CreateTimer(ClrSyncManager manager, Original::TimerCallback timerCallback, object state, TimeSpan dueTime, TimeSpan period) { TimerRoutineArg argument = new TimerRoutineArg(); argument.callback = timerCallback; argument.state = state; argument.dueTime = dueTime; argument.Period = period; argument.selfSemaphore = new Semaphore(0, 1); argument.parentSemaphore = new Semaphore(0, 1); argument.disposed = false; argument.changed = true; Timer ret = new Timer(TimerCreateWrapper, argument, 0, Timeout.Infinite); argument.timer = ret; timer2tra.Add(ret, argument); int child = manager.TaskFork(); argument.parentSemaphore.WaitOne(); manager.RegisterTaskSemaphore(child, argument.selfSemaphore, false); manager.TaskResume(child); return(ret); }