c# - Should I use thread to improve performance in these code? -


in coding, want performance improvement, think thread choice, not confident multithreading , data sharing issue. review these codes , give me sugguestions, thanks!

 public partial class workflowservice: iworkflowservice  {          public void startprocess(wfapprunner starter)             {                 try                 {                     wfruntimemanager runtimemanager = new wfruntimemanagerstartup();                     runtimemanager.apprunner = starter;                     runtimemanager.execute();                 }                 catch (system.exception)                 {                     throw;                 }             }  }  internal abstract class wfruntimemanager {         internal wfapprunner apprunner { get; set; }         internal abstract void executeinstance();         internal bool execute()         {             try             {                 thread thread = new thread(executeinstance);                 thread.start();                  return true;             }             catch (system.exception)             {                 throw;             }         } }  internal class wfruntimemanagerstartup : wfruntimemanager {     internal override void executeinstance()     {         isession session = sessionfactory.createsession();         try         {             var runner = base.apprunner;              //do works runner, , save works database.             savetodatabase(runner);          ...          //do other works         processotherworks();              session.commit();         }         catch (system.exception)         {             session.rollback();         }                 {             session.dispose();         }     } }  //do test, minic true user case [testmethod] public void runparalleled() {     //startera:     //{"userid":"10","username":"long","appname":"sampleprice","appinstanceid":"100","processguid":"072af8c3-482a-4b1c-890b-685ce2fcc75d"}     var startera = new wfapprunner();     startera.processguid = guid.parse("072af8c3-482a-4b1c-890b-685ce2fcc75d");     startera.userid = 10;     startera.username = "long";      //sarterb:     //{"appname":"offin","appinstanceid":587,"userid":"0021","username":"test2","processguid":"68696ea3-00ab-4b40-8fcf-9859dbbde378","flowstatus":null,"conditions":{"surplus":"aa"}}     var starterb = new wfapprunner();     starterb.processguid = guid.parse("68696ea3-00ab-4b40-8fcf-9859dbbde378");     starterb.userid = 21;     starterb.username = "test2";      iworkflowservice servicea, serviceb;     (var = 0; < 5000; i++)     {         servicea = new workflowservice();         startera.appname = "price";         startera.appinstanceid = i;          serviceb = new workflowservice();         starterb.appname = "offin";         starterb.appinstanceid = i;          //execute process instance         servicea.startprocess(startera);         serviceb.startprocess(starterb);     } } 


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -