c# - Call long running method and continue with other tasks -


public class performmaintask() {     task1();     task2();     performlongtask();     task3();     task4(); } 

what achieve here performlongtask() onto thread, , continue task3 & task4 when performlongtask() still running.

how should performlongtask() in c# 5.0 way?

do need use async/await?

the simplest solution know of is:

task1(); task2(); var task3 = task.run(() => performlongtask()); task4(); task5(); task3.wait(); //if task3 has not started yet inlined here 

simple , efficient. if need propagate errors should use parallel.invoke:

parallel.invoke(  () => { performlongtask(); },  () => { task4(); task5(); } ); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -