C#.Rihter.ParentTasks
Example
static void Main(string[] args) { Task<Int32[]> parent = new Task<Int32[]>(() => { var results = new Int32[3]; StartNewTask(results, 0, 1); StartNewTask(results, 1, 2);
Example
static void Main(string[] args) { Task<Int32[]> parent = new Task<Int32[]>(() => { var results = new Int32[3]; StartNewTask(results, 0, 1); StartNewTask(results, 1, 2);
static void Main(string[] args) { Task<int> t = new Task<int>(Work); t.Start(); Thread.Sleep(3000); // doing smth in main thread t.ContinueWith(t => Console.WriteLine(«job is done «
task allows get result
static void Main(string[] args) { Task<int> t = new Task<int>(n => Sum((int) n), 10000); t.Start(); t.Wait(); Console.WriteLine(«The sum is «
how do i exit from thread
static void Main(string[] args) { var tokenSource = new CancellationTokenSource(); ThreadPool.QueueUserWorkItem(o => ThreadWorker(tokenSource.Token, 1000)); Console.WriteLine(«Press <Enter> to cancel
static void Main(string[] args) { Console.WriteLine(«this is main thread»); ThreadPool.QueueUserWorkItem(ThreadWorker, 123); Thread.Sleep(3000); } private static void ThreadWorker(object obj) { Thread.Sleep(1000); Console.WriteLine(«hi from thread pool
Foreground and background threads.
If background thread then application will not wait until it is over, in other case it will.
static void
static void Main(string[] args) { Console.WriteLine(«inside thread id » + Thread.CurrentThread.ManagedThreadId); var otherThread = new Thread(ThreadWork); otherThread.Priority = ThreadPriority.Normal; otherThread.Start(5); otherThread.Join(); // wait for
Both, reject and throw can be handled with catch
reject inside promise will be handled by 2-d argument of then, and if it is
const
const Pi = 3.14;
SCOPING
block-scoped variables
// es 6 for (let i = 0; i < 10; i ++) { let x =
Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n =