Click here to Skip to main content
15,894,240 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have this code how can i writ this code in saperate file plz help me
C#
public partial class Service1 : ServiceBase
    {

        public string AppPath = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).ToString()).ToString();
        Timer timer = new Timer();
        Voucher vocher;
        private DataSet ds;

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            //WebServiceMethod("start service");
            WebServiceMethod();
            //handle Elapsed event
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            //This statement is used to set interval to 5 minute (= 3,00,000 milliseconds)
            timer.Interval = 300000;
            //enabling the timer
            timer.Enabled = true;
        }

        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            //WebServiceMethod("Another entry at " + DateTime.Now);
            WebServiceMethod();
        }

        protected override void OnStop()
        {
            timer.Enabled = false;
            //WebServiceMethod("stopping service");
            WebServiceMethod();
        }

        private void WebServiceMethod(string content = "")
        {
            WebServiceProxyMethod();

        }


        internal void WebServiceProxyMethod()
        {
            try
            {
                vocher = new Voucher();
                vocher.Credentials = new System.Net.NetworkCredential("000", "000");
                XmlNode xmlnode = vocher.VoucherExport();

                XmlReader xmlReader = new XmlNodeReader(xmlnode);
                using (ds = new DataSet())
                {
                    ds.ReadXml(xmlReader);
                    DataTable dt = ds.Tables["TableName"];
                    if (dt != null)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                        }
                    }
                }
            }
            catch (SoapException ex)
            {
                ErrorLog(ex.Message, ex.StackTrace);
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message, ex.StackTrace);
            }
        }
Posted
Updated 29-Nov-12 18:29pm
v2
Comments
[no name] 30-Nov-12 0:31am    
How ????

1 solution

Write in a separate file:
C#
public partial class Service1 { // important: no need to repeat ": ServiceBase"
    // some more declarations/definitions...
}


Naturally, add some "using" in the very beginning if you want to, but you need to add only namespaces you use in your declarations/definitions in this file.

This is how "partial" works.

[EDIT]

One note: never ever use names like "Service1". No numeric characters in names! This is not a mistake, but a bad violation of (good) Microsoft naming recommendations. All names should be semantic. In particular, never use auto-generated names. This is why you are given a refactorization engine.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900