예제 #1
0
 protected async Task <Result <T> > TryExecuteWithLoadingIndicatorsAsync <T>(
     Task <T> operation,
     Func <Exception, Task <bool> > onError = null) =>
 await TaskHelper.Create()
 .WhenStarting(() => IsBusy = true)
 .WhenFinished(() => IsBusy = false)
 .TryWithErrorHandlingAsync(operation, onError);
 public ActionResult Create(int ProjectId, string Name, string Content, string UserId, DateTime Deadline, Priority Priority, string Comment)
 {
     if (ModelState.IsValid)
     {
         TaskHelper.Create(ProjectId, Name, Content, UserId, Deadline, Priority, Comment);
         return(RedirectToAction("Index", "Projects"));
     }
     ViewBag.UserId = new SelectList(TaskHelper.GetListOfUsers(), "Id", "Email");
     return(View());
 }
예제 #3
0
        async DispatcherTest()
        {
            // download the google home page
            WebClient client = new WebClient();
            var       google = client.DownloadStringTask("http://www.google.com");

            yield return(google);

            // find and download the first link on the google home page
            Regex regex         = new Regex("href=\"(?<href>http://.*?)\"");
            var   match         = regex.Match(google.Result);
            var   firstHref     = match.Groups["href"].Value;
            var   firstHrefTask = TaskHelper.Create(client.DownloadString, firstHref);

            yield return(firstHrefTask);

            // let's yield back onto the Dispatcher to get onto the UI thread
            yield return(this.Dispatcher());

            textBox1.Text = firstHrefTask.Result;
        }
예제 #4
0
        // Use this for initialization
        void Start()
        {
            //DontDestroyOnLoad(gameObject);

            // 场景切换以后停止执行
            #region
            this.Delay(1, () => {
                Log.I(this, "延迟1s执行");
            });

            this.ExcuteTask(new WaitForSeconds(5), () => {
                Log.I(this, "延迟5s执行");
            }).Name("task 1");

            CoroutineTask coroutineTask = TaskHelper.Create <CoroutineTask>()
                                          .SetMonoBehaviour(this)
                                          .Delay(6)
                                          .Name("task 2")
                                          .OnStart(() => { Log.I(this, "coroutineTask [Onstart], {0}", Time.realtimeSinceStartup); })
                                          .Do(() => { Log.I(this, "coroutineTask [Do], {0}", Time.realtimeSinceStartup); })
                                          .OnFinish(() => { Log.I(this, "coroutineTask [onfinish] {0}", Time.realtimeSinceStartup); })
                                          .OnCancle(() => { Log.I(this, "coroutineTask [oncancle] {0}", Time.realtimeSinceStartup); })
                                          .Execute();

            coroutineTask.Cancle();

            TaskHelper.Create <CoroutineTask>()
            .Name("task 2")
            .SetMonoBehaviour(this)
            .Delay(6)
            .Do(() => { Log.I(this, "coroutineTask6 [Do], {0}", Time.realtimeSinceStartup); })
            .Delay(3)
            .Do(() => { Log.I(this, "coroutineTask9 [Do], {0}", Time.realtimeSinceStartup); })
            .Execute();

            coroutineTask = TaskHelper.Create <CoroutineTask>()
                            .Name("task test")
                            .SetMonoBehaviour(this)
                            .Delay(TestA(), TestB())
                            .Do(() => { Log.I(this, "task test [Do], {0}", Time.realtimeSinceStartup); })
                            .Execute();
            #endregion

            //// 场景切换以后会继续执行
            TaskHelper.Create <CoroutineTask>()
            .Delay(5)
            .Name("task 5")
            .Do(() => { Log.I(this, "coroutineTask 5 [Do]"); })
            .Execute();

            TaskHelper.Create <RunableTask>()
            .Delay(10)
            .Name("task 3")
            .OnStart(() => { Log.I(this, "threadTask [Onstart], {0}", System.DateTime.Now); })
            .Do(() => { Log.I(this, "threadTask [Do], {0}", System.DateTime.Now); })     // Do将在其他线程运行, 使用Time.realtimeSinceStartup会Crash
            .OnFinish(() => { Log.I(this, "threadTask [OnFinish] {0}", System.DateTime.Now); })
            .OnCancle(() => { Log.I(this, "threadTask [OnCancle] {0}", System.DateTime.Now); })
            .Execute();

            // threadTask.Cancle();
        }