public long Demo(long val) { return Task.Factory.StartNew(() => { long a = 0; for (int i = 0; i < val; i++) { a += i; } return a; }).ContinueWith<long>(t => { return t.Result; }).Result; }