コード例 #1
0
                    public zz(IAppOther page)
                    {
                        Native.document.title = "zz";
                        #region go 2
                        new IHTMLButton { innerText = "go 2" }.AttachToDocument().WhenClicked(
                            //async
                         delegate
                         {
                             // hsc, why wont lambda declaration work within async scope?

                             // http://blogs.msdn.com/b/dotnet/archive/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis.aspx

                             Console.WriteLine("before");

                             // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201309-1/20130904-iprogress
                             //var x =
                             //await 
                             Task.Factory.StartNewWithProgress(

                             new { value = "world!" },

                             progress:
                                xx =>
                                {
                                    Console.WriteLine("DOM Progress: " + new { xx.value, Thread.CurrentThread.ManagedThreadId });

                                    Native.document.title = new { xx.value, Thread.CurrentThread.ManagedThreadId }.ToString();
                                },

                             function:
                                 scope =>
                                 {
                                     #region scope is null
                                     if (scope == null)
                                     {
                                         // { x = scope_progress is null { state = [object Object], BackgroundThread = 10 }, ManagedThreadId = 1 }
                                         return new { value = "scope is null " + new { BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                     }
                                     #endregion



                                     var state = scope.Item2;

                                     #region scope_progress
                                     var scope_progress = scope.Item1;
                                     if (scope_progress == null)
                                     {
                                         // { x = null { BackgroundThread = 10 }, ManagedThreadId = 1 }
                                         return new { value = "scope_progress is null " + new { state, BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                     }
                                     #endregion

                                     var e = new Stopwatch();
                                     e.Start();

                                     scope_progress.Report(
                                          new
                                          {
                                              value = "hi " + new { e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId }
                                          }
                                     );


                                     for (int i = 0; i < 20; i++)
                                     {
                                         scope_progress.Report(
                                            new
                                            {
                                                value = ". " + new { i, state.value, e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId }
                                            }
                                         );

                                         Thread.Sleep(100);
                                     }


                                     return new { value = "done " + new { e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                 }
                         ).ContinueWithResult(
                             x =>
                             {
                                 Console.WriteLine("after");
                                 Native.document.title = new { x.value, Thread.CurrentThread.ManagedThreadId }.ToString();
                             }
                         );

                         }
                     );
                        #endregion


                        new IHTMLButton { innerText = "replaceState", id = "replaceState" }.AttachToDocument().WhenClicked(
                            btn =>
                            {
                                Native.window.history.replaceState(
                                    new { replaceState = "world", btn.id },
                                    scope =>
                                    {
                                        ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;

                                        Native.document.title = "zz " + new { scope.state.replaceState };

                                    }
                                );
                            }
                        );

                        #region options
                        new IHTMLButton { innerText = "pushState1", id = "pushState1" }.AttachToDocument().WhenClicked(
                            btn =>
                            {

                                Native.window.history.pushState(
                                    new { pushState = "world1", btn.id },
                                    async scope =>
                                    {
                                        ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;
                                        Native.document.title = "zz " + new { scope.state.pushState };
                                        var x = new { Native.document.body.style.backgroundColor };
                                        Native.document.body.style.backgroundColor = "yellow";

                                        await scope;
                                        //scope.TaskCompletionSource.Task.ContinueWithResult(
                                        //    delegate
                                        //    {

                                        Native.document.body.style.backgroundColor = x.backgroundColor;

                                        ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = false;
                                        Native.document.title = "zz!";
                                        //    }
                                        //);
                                    }
                                );
                            }
                        );


                        new IHTMLButton { innerText = "pushState2", id = "pushState2" }.AttachToDocument().WhenClicked(
                            btn =>
                            {

                                Native.window.history.pushState(
                                    new { pushState = "world2", btn.id },
                                    async scope =>
                                    {
                                        ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = true;
                                        Native.document.title = "zz " + new { scope.state.pushState };

                                        var x = new { Native.document.body.style.backgroundColor };
                                        Native.document.body.style.backgroundColor = "green";

                                        await scope;


                                        Native.document.body.style.backgroundColor = x.backgroundColor;

                                        ((IHTMLButton)Native.document.getElementById(scope.state.id)).disabled = false;
                                        Native.document.title = "zz!";
                                    }
                                );
                            }
                        );
                        #endregion


                    }
コード例 #2
0
                    public z(IAppOther page)
                    {
                        Native.document.title = "z";

                        #region go 2
                        new IHTMLButton { innerText = "go 2" }.AttachToDocument().WhenClicked(
                            //async
                         delegate
                         {
                             // hsc, why wont lambda declaration work within async scope?

                             // http://blogs.msdn.com/b/dotnet/archive/2012/06/06/async-in-4-5-enabling-progress-and-cancellation-in-async-apis.aspx

                             Console.WriteLine("before");

                             // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201309-1/20130904-iprogress
                             //var x =
                             //await 
                             Task.Factory.StartNewWithProgress(

                             new { value = "world!" },

                             progress:
                                xx =>
                                {
                                    Console.WriteLine("DOM Progress: " + new { xx.value, Thread.CurrentThread.ManagedThreadId });

                                    Native.document.title = new { xx.value, Thread.CurrentThread.ManagedThreadId }.ToString();
                                },

                             function:
                                 scope =>
                                 {
                                     #region scope is null
                                     if (scope == null)
                                     {
                                         // { x = scope_progress is null { state = [object Object], BackgroundThread = 10 }, ManagedThreadId = 1 }
                                         return new { value = "scope is null " + new { BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                     }
                                     #endregion



                                     var state = scope.Item2;

                                     #region scope_progress
                                     var scope_progress = scope.Item1;
                                     if (scope_progress == null)
                                     {
                                         // { x = null { BackgroundThread = 10 }, ManagedThreadId = 1 }
                                         return new { value = "scope_progress is null " + new { state, BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                     }
                                     #endregion

                                     var e = new Stopwatch();
                                     e.Start();

                                     scope_progress.Report(
                                          new
                                          {
                                              value = "hi " + new { e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId }
                                          }
                                     );


                                     for (int i = 0; i < 20; i++)
                                     {
                                         scope_progress.Report(
                                            new
                                            {
                                                value = ". " + new { i, state.value, e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId }
                                            }
                                         );

                                         Thread.Sleep(100);
                                     }


                                     return new { value = "done " + new { e.ElapsedMilliseconds, BackgroundThread = Thread.CurrentThread.ManagedThreadId } };
                                 }
                         ).ContinueWithResult(
                             x =>
                             {
                                 Console.WriteLine("after");
                                 Native.document.title = new { x.value, Thread.CurrentThread.ManagedThreadId }.ToString();
                             }
                         );

                         }
                     );
                        #endregion


                    }