private void listView_Click(object sender, EventArgs e) { Point mousePos = listView.PointToClient(Control.MousePosition); ListViewHitTestInfo hitTest = listView.HitTest(mousePos); int columnIndex = hitTest.Item.SubItems.IndexOf(hitTest.SubItem); if (columnIndex == 1) { MyTask task = hitTest.Item.Tag as MyTask; if (m_mainForm.SimulationHandler.CanStart && task.Enabled && task.DesignTime) { task.Execute(); } } }
public void TestMethodSomeTask() { ThreadPool.ThreadPool threadPool = new ThreadPool.ThreadPool(new Random(), 4); MyTask <int> task1 = new MyTask <int>(() => 2 + 2); MyTask <int> task2 = new MyTask <int>(() => { int x = 0; return(1 / x); }); MyTask <String> task3 = new MyTask <String>(() => "Task3"); threadPool.Enqueue(task1); threadPool.Enqueue(task2); threadPool.Enqueue(task3); threadPool.Start(); Thread.Sleep(1000); threadPool.Dispose(); Assert.AreEqual(4, task1.Result()); Assert.ThrowsException <AggregateException>(() => task2.Execute()); Assert.AreEqual("Task3", task3.Result()); }
protected void loadData() { var Endpoint = "http://47.91.249.226:8000/api/Video/GetAllVideos"; MyTask myTask = new MyTask(); myTask.SetLitener(this); myTask.Execute(Endpoint); //启动异步任务 //Action action = () => //{ // OkHttpClient client = new OkHttpClient(); // // Create request for remote resource. // Request request = new Request.Builder() // .Url(Endpoint) // .Build(); // // Execute the request and retrieve the response. // Response response = client.NewCall(request).ExecuteAsync().Result; // // Deserialize HTTP response to concrete type. // string body = response.Body().StringAsync().Result; // list = new List<VideoModel>(); // list = JsonConvert.DeserializeObject<List<VideoModel>>(body); //}; _myHandler = new MyHandler(GetValue); //在主线程实例化一个Handler对象 //RetrofitHelper.getBiliAppAPI() // .getVideoDetails(av) // .compose(this.bindToLifecycle()) // .subscribeOn(Schedulers.io()) // .observeOn(AndroidSchedulers.mainThread()) // .subscribe(videoDetails-> { // mVideoDetailsInfo = videoDetails.getData(); // finishTask(); //}, throwable-> { //}); finishTask(); }
public float GetError() { // get the error from output layer if (LastLayer is MyAbstractOutputLayer) { // pointer to output layer MyAbstractOutputLayer outputLayer = LastLayer as MyAbstractOutputLayer; // get enabled loss function MyTask lossTask = outputLayer.GetEnabledTask("LossFunctions"); // no loss function? if (lossTask == null) { // Get call stack StackTrace stackTrace = new StackTrace(); MyLog.ERROR.WriteLine("ERROR: GetError() called from " + stackTrace.GetFrame(1).GetMethod().Name + " needs a LossFunction task to be selected in the OutputLayer."); return(0.0f); } // execute loss function lossTask.Execute(); // copy to host outputLayer.Cost.SafeCopyToHost(); // return cost (error) return(outputLayer.Cost.Host[0]); } else { // Get call stack StackTrace stackTrace = new StackTrace(); MyLog.ERROR.WriteLine("ERROR: GetError() called from " + stackTrace.GetFrame(1).GetMethod().Name + " needs an OutputLayer as the last layer."); return(0.0f); } }