コード例 #1
0
        public static bool InternalWorkerInvoke(Sprite that)
        {
            var magic = (string)Worker.current.getSharedProperty("InternalWorkerInvoke");

            if (magic != "Run(Func<Task<TResult>>)")
            {
                return(false);
            }

            #region xfromWorkerConsole
            // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs
            var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole");

            var w = new __Console.__OutWriter
            {
                AtWriteLine = z =>
                {
                    xfromWorkerConsole.send(z);
                }
            };

            Console.SetOut(w);
            #endregion


            var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName");
            var FunctionToken_MethodName   = (string)Worker.current.getSharedProperty("FunctionToken_MethodName");

            IntPtr pp = __IntPtr.OfFunctionToken(null,
                                                 FunctionToken_TypeFullName,
                                                 FunctionToken_MethodName
                                                 );


            MethodInfo mm = new __MethodInfo {
                _Method = pp
            };

            //    t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds };

            //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName });

            //throw null;



            // we are on a worker thread.
            // are we able to await and then respond and terminate?
            var value = (Task <object>)mm.Invoke(null, new object[] { });

            value.ContinueWith(
                task =>
            {
                // is the return type transerable?
                // or would we have to serialize it?

                var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker");
                // or are we to capture all fields modified within worker and only update those?
                xfromWorker.send(task.Result);
            }
                );



            return(true);
        }
コード例 #2
0
        public static bool InternalWorkerInvoke(Sprite that)
        {
            // pop ?

            if (Worker.current.isPrimordial)
            {
                InternalPrimordialSprite = that;
                return(false);
            }

            // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs
            InternalWorkerSprite = that;

            if (__Task.InternalWorkerInvoke(that))
            {
                // X:\jsc.svn\examples\actionscript\async\Test\TestAsyncTaskRun\TestAsyncTaskRun\ApplicationSprite.cs
                // Task.Run called itself

                return(true);
            }


            #region xfromWorkerConsole
            // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs
            var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole");

            var w = new __Console.__OutWriter
            {
                AtWriteLine = z =>
                {
                    xfromWorkerConsole.send(z);
                }
            };

            Console.SetOut(w);
            #endregion



            // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs

            // are we inside worker?

            var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName");
            var FunctionToken_MethodName   = (string)Worker.current.getSharedProperty("FunctionToken_MethodName");
            var arg0 = (string)Worker.current.getSharedProperty("arg0");

            IntPtr pp = __IntPtr.OfFunctionToken(null,
                                                 FunctionToken_TypeFullName,
                                                 FunctionToken_MethodName
                                                 );


            MethodInfo mm = new __MethodInfo {
                _Method = pp
            };

            //    t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds };

            //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName });

            //throw null;


            try
            {
                mm.Invoke(null, new object[] { arg0 });
            }
            catch (Exception err)
            {
                // lets report anything back to the app
                // for now the best we can do is to print it to console in worker
                // and hope the app is showing the console in textfield

                //__Thread.InternalWorkerSprite.loaderInfo.uncaughtErrorEvents.uncaughtError +=
                // does not seem to work yet?

                Console.WriteLine("catch " + new { err });
                // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs
            }


            return(true);
        }
コード例 #3
0
        public static bool InternalWorkerInvoke(Sprite that)
        {
            // pop ?

            if (Worker.current.isPrimordial)
            {
                InternalPrimordialSprite = that;
                return false;
            }

            // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs
            InternalWorkerSprite = that;

            if (__Task.InternalWorkerInvoke(that))
            {
                // X:\jsc.svn\examples\actionscript\async\Test\TestAsyncTaskRun\TestAsyncTaskRun\ApplicationSprite.cs
                // Task.Run called itself

                return true;
            }


            #region xfromWorkerConsole
            // X:\jsc.svn\examples\actionscript\Test\TestWorkerConsole\TestWorkerConsole\ApplicationSprite.cs
            var xfromWorkerConsole = (MessageChannel)Worker.current.getSharedProperty("fromWorkerConsole");

            var w = new __Console.__OutWriter
            {
                AtWriteLine = z =>
                {
                    xfromWorkerConsole.send(z);
                }
            };

            Console.SetOut(w);
            #endregion



            // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs

            // are we inside worker?

            var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName");
            var FunctionToken_MethodName = (string)Worker.current.getSharedProperty("FunctionToken_MethodName");
            var arg0 = (string)Worker.current.getSharedProperty("arg0");

            IntPtr pp = __IntPtr.OfFunctionToken(null,
                 FunctionToken_TypeFullName,
                 FunctionToken_MethodName
             );


            MethodInfo mm = new __MethodInfo { _Method = pp };

            //    t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds };

            //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName });

            //throw null;


            try
            {

                mm.Invoke(null, new object[] { arg0 });

            }
            catch (Exception err)
            {
                // lets report anything back to the app
                // for now the best we can do is to print it to console in worker
                // and hope the app is showing the console in textfield

                //__Thread.InternalWorkerSprite.loaderInfo.uncaughtErrorEvents.uncaughtError +=
                // does not seem to work yet?

                Console.WriteLine("catch " + new { err });
                // X:\jsc.svn\examples\actionscript\Test\TestWorkerThrow\TestWorkerThrow\ApplicationSprite.cs
            }


            return true;
        }