c# - Task does not wait up-to the wait time -


i have created task , provided wait time in task.wait() method, task not wait upto provided time , return before wait time completed status false.

var task = task<int>.factory.startnew(() =>     {         int result;         result = getsomevalue();         return result;     });     task.wait(2000);      if(task.iscompleted)     {         //taks copleted     }     else     {         //task not completed     }      private int getsomevalue()     {         //do somethings         //i have printed time take function         //it not more 200 milliseconds         return somevalue;     } 

when run code, else part executed. have added log time taken "getsomevalue()" function , not taking more 200 milliseconds.

i don't know wrong code?

note: running code in 4.0 framework.

if need wait task completion, can use property result. result property blocks calling thread until task finishes.

var task = task<int>.factory.startnew(() => getsomevalue()); int res = task.result;


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -