multithreading - Threading in C# issue -


i have piece of code runs 1 method , runs same method again different parameters. method takes 45 seconds complete minute , half in total. looks like:

//start dbinfopackage migrateddata = runfirstqueries(connectsqlserver, log); dbinfopackage nonmigrateddata = runfirstqueries(connectoracle, log); //end 

is possible run methods @ same time using threading?

just since people giving lower-level answers, using system.threading.thread , whatnot, i'd do:

task<dbinfopackage> migrateddatatask = task.run<dbinfopackage>(() => runfirstqueries(connectsqlserver, log)); task<dbinfopackage> nonmigrateddatatask = task.run<dbinfopackage>(() => runfirstqueries(connectoracle, log));  task.waitall(migrateddatatask, nonmigrateddatatask);  var migrateddata = migrateddatatask.result; var nonmigrateddata = nonmigrateddatatask.result; 

that'll run them in 2 concurrent tasks, wait them both finish, , grab results. you'll want add in error handling, that's easy enough.

if can work workflow (and can), it's better use await task.whenall(migrateddatatask, nonmigrateddatatask) instead of waitall, used latter in example sustain thread-blocking behavior.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -