c# - Repeatedly running a function in a Windows Service -


hello friends i'm working c#.net web application used windows service work expected in 1 time per day... requirement check every 5 minutes more how possible

    using system;      using system.collections.generic;      using system.componentmodel;      using system.data;     using system.data.sqlclient;     using system.diagnostics;     using system.linq;     using system.serviceprocess;     using system.text;     using docusignapi;     using system.timers;     using system.threading     namespace testservice     {         public partial class service1 : servicebase         {              static string strdocusignusername;             static string strdocusignpassword;             static string strdocusignintegratorkey;             sqlconnection sqlcon;            docusignapi api = new docusignapi();             public service1()             {                 initializecomponent();  }          protected override void onstart(string[] args)         {             try             {                 line();             }             catch             {              }              try             {                 threadstart tstask = new threadstart(process);                 thread mytask = new thread(tstask);                 mytask.start();             }             catch             {             }           }          protected override void onstop()         {         }         public void process()         {              //onstart(null);             line();              system.threading.thread.sleep(timespan.fromminutes(5));          }          public void line()         {             try             {                  //if (sqlcon.state == connectionstate.open)                 //{                 //    sqlcon.close();                 //}                 sqlcon = new sqlconnection(@"data source=tech-vm-tworks2\sqlexpress;initial catalog=twmaster;integrated security=true;user id=;password=;");                 sqlcon.open();                  datatable dt_docusignuser = new datatable();                 string str = "select docusignuser,docusignpwd,docusignintegratorkey globaldefaults id=1";                 sqldataadapter adp_docusignuser = new sqldataadapter(str, sqlcon);                 adp_docusignuser.fill(dt_docusignuser);                   foreach (datarow row in dt_docusignuser.rows)                 {                     strdocusignusername = row["docusignuser"].tostring();                     strdocusignpassword = row["docusignpwd"].tostring();                     strdocusignintegratorkey = row["docusignintegratorkey"].tostring();                 }                  datatable dt_linkselect = new datatable();                 str = "select link,link2,left(cast(link nvarchar(2000)),len(cast(link nvarchar(2000))) - charindex('\\',reverse(cast(link varchar(1000))))) linkpath,ancillary_id,docusign_env_id,env_status docusignmapping , ancillary env_status =1 , docusignmapping.ancillary_id = ancillary.id";                 sqldataadapter adp_link = new sqldataadapter(str, sqlcon);                 adp_link.fill(dt_linkselect);                  foreach (datarow row in dt_linkselect.rows)                 {                     string strtablelinkpath = row["linkpath"].tostring();                     string envelopeid = row["docusign_env_id"].tostring();                        if (strtablelinkpath.length > 0)                     {                         if (api.docusign_envidinf(strdocusignusername, strdocusignpassword, strdocusignintegratorkey, envelopeid) == true)                         {                              if (api.docusign_download(strdocusignusername, strdocusignpassword, strdocusignintegratorkey, envelopeid, strtablelinkpath) == true)                             {                                 sqlcommand spcmd = new sqlcommand("updatedocusignlinks_ancillary", sqlcon);                                 spcmd.commandtype = commandtype.storedprocedure;                                  sqlparameter docusignenvelopid = new sqlparameter("@docusignenvelopid", sqldbtype.nvarchar);                                 docusignenvelopid.value = convert.tostring(envelopeid);                                  sqlparameter envelopeaddress = new sqlparameter("@envelopeaddress", sqldbtype.nvarchar);                                 envelopeaddress.value = convert.tostring(strtablelinkpath + '\\' + envelopeid + '1' + ".pdf");                                  spcmd.parameters.add(docusignenvelopid);                                 spcmd.parameters.add(envelopeaddress);                                  // log purpose                                   spcmd.executenonquery();                              }                         }                         else                         {                             sqlcon.close();                          }                       }                  }               }             catch              {              }                if (sqlcon.state == connectionstate.open)             {                 sqlcon.close();             }         }     } } 

it code friends

im using dll file in web application class name docusign , set object api im used thread not work correctly 1 can me friends ......

my requirements connect db status 1 called api.docusign_envidinf(,,,,) , completed next true passing boolean value , goto download working correctly working service starting time after service started not checked status , not download process how call function repeatably in windows service

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.data.sqlclient; using system.diagnostics; using system.linq; using system.serviceprocess; using system.text; using docusignapi; using system.timers; using system.configuration;     namespace testservice {     public partial class service1 : servicebase     {          static string strdocusignusername;         static string strdocusignpassword;         static string strdocusignintegratorkey;         sqlconnection sqlcon; // sql global variable declare             system.timers.timer timer = new system.timers.timer();         docusignapi api = new docusignapi(); // call dll class in sservice         public service1()         {             initializecomponent();             this.canstop = true;          //intialize main entry point firing timer             this.canpauseandcontinue = true;           }           //public void ondebug()         //{         //    onstart(null);         //    onstop();          //}             protected override void onstart(string[] args)         {             timer.enabled = true;             timer.interval = 10000;             timer.elapsed += new system.timers.elapsedeventhandler(timer_elapsed);            }          protected override void onstop()         {         }           protected void timer_elapsed(object source, system.timers.elapsedeventargs aa)         {              try             {                   string connectionstring = configurationmanager.connectionstrings["lawex"].connectionstring;                 sqlcon = new sqlconnection(connectionstring);                 sqlcon.open();                  datatable dt_docusignuser = new datatable();                 string str = "select docusignuser,docusignpwd,docusignintegratorkey globaldefaults id=1";                 sqldataadapter adp_docusignuser = new sqldataadapter(str, sqlcon);                 adp_docusignuser.fill(dt_docusignuser);                   foreach (datarow row in dt_docusignuser.rows)                 {                     strdocusignusername = row["docusignuser"].tostring();                     strdocusignpassword = row["docusignpwd"].tostring();                     strdocusignintegratorkey = row["docusignintegratorkey"].tostring();                 }                  datatable dt_linkselect = new datatable();                 str = "select link,link2,left(cast(link nvarchar(2000)),len(cast(link nvarchar(2000))) - charindex('\\',reverse(cast(link varchar(1000))))) linkpath,ancillary_id,docusign_env_id,env_status docusignmapping , ancillary env_status =1 , docusignmapping.ancillary_id = ancillary.id";                 sqldataadapter adp_link = new sqldataadapter(str, sqlcon);                 adp_link.fill(dt_linkselect);                  foreach (datarow row in dt_linkselect.rows)                 {                     string strtablelinkpath = row["linkpath"].tostring();                     string envelopeid = row["docusign_env_id"].tostring();                        if (strtablelinkpath.length > 0)                     {                         if (api.docusign_envidinf(strdocusignusername, strdocusignpassword, strdocusignintegratorkey, envelopeid) == true)                         {                              if (api.docusign_download(strdocusignusername, strdocusignpassword, strdocusignintegratorkey, envelopeid, strtablelinkpath) == true)                             {                                 sqlcommand spcmd = new sqlcommand("updatedocusignlinks_ancillary", sqlcon);                                 spcmd.commandtype = commandtype.storedprocedure;                                  sqlparameter docusignenvelopid = new sqlparameter("@docusignenvelopid", sqldbtype.nvarchar);                                 docusignenvelopid.value = convert.tostring(envelopeid);                                  sqlparameter envelopeaddress = new sqlparameter("@envelopeaddress", sqldbtype.nvarchar);                                 envelopeaddress.value = convert.tostring(strtablelinkpath + '\\' + envelopeid + '1' + ".pdf");                                  spcmd.parameters.add(docusignenvelopid);                                 spcmd.parameters.add(envelopeaddress);                                  // log purpose                                   spcmd.executenonquery();                              }                         }                         else                         {                             sqlcon.close();                          }                       }                  }               }             catch              {              }                if (sqlcon.state == connectionstate.open)             {                 sqlcon.close();             }          }         }  } 

Comments