示例#1
0
        public static object Sleep(int seconds)
        {
            // The callerFunctionName and callerParameters are internally combined and used as a 'key'
            // to link the underlying RTD calls together.
            string callerFunctionName = "Sleep";
            object callerParameters   = new object[] { seconds }; // This need not be an array if it's just a single parameter

            return(AsyncTaskUtil.RunAsTask(callerFunctionName, callerParameters, _fourThreadFactory, () =>
            {
                Thread.Sleep(seconds * 1000);
                return "Slept on Thread " + Thread.CurrentThread.ManagedThreadId;
            }));
        }
示例#2
0
        public static object SleepPerCaller(int seconds)
        {
            // Trick to get each call to be a separate instance
            // Normally you only want to add the actual parameters passed in
            object callerReference    = XlCall.Excel(XlCall.xlfCaller);
            string callerFunctionName = "SleepPerCaller";
            object callerParameters   = new object[] { seconds, callerReference };

            // The RunTask version (instead of RunAsTask used above) is more flexible if the Task will be created in some other way.
            return(AsyncTaskUtil.RunTask(callerFunctionName, callerParameters, () =>
            {
                // The function here should return the Task to run
                return _fourThreadFactory.StartNew(() =>
                {
                    Thread.Sleep(seconds * 1000);
                    return string.Format("Slept on Thread {0}, called from {1}", Thread.CurrentThread.ManagedThreadId, callerReference);
                });
            }));
        }
示例#3
0
 // This is what the Task wrappers that is generated looks like.
 // Can use the same Task helper here.
 public static object dnaExplicitWrap(string name, int msDelay)
 {
     return(AsyncTaskUtil.RunTask("dnaExplicitWrap", new object[] { name, msDelay }, () => dnaDelayedTaskHello(name, msDelay)));
 }