Click here to Skip to main content
15,867,991 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk36-Jan-18 6:17
turbosupramk36-Jan-18 6:17 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
turbosupramk36-Jan-18 12:09
turbosupramk36-Jan-18 12:09 
GeneralRe: Problem with setwindowPOS and returning from topmost to standard window position? Pin
Richard MacCutchan6-Jan-18 20:44
mveRichard MacCutchan6-Jan-18 20:44 
Questionusing MVC in WPF Pin
abboudi_ammar1-Jan-18 5:38
abboudi_ammar1-Jan-18 5:38 
AnswerRe: using MVC in WPF Pin
Dave Kreskowiak1-Jan-18 6:16
mveDave Kreskowiak1-Jan-18 6:16 
GeneralRe: using MVC in WPF Pin
abboudi_ammar1-Jan-18 6:24
abboudi_ammar1-Jan-18 6:24 
GeneralRe: using MVC in WPF Pin
Dave Kreskowiak1-Jan-18 7:27
mveDave Kreskowiak1-Jan-18 7:27 
Questionstruck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 2:33
Mohiyuddin Khan1-Jan-18 2:33 
hi all
I have created in windows application and also one windows service using c#. this windows application has the database connection and do some functions etc which i want to daily repeat. so i have created the windows service. when i debug windows service in debug mode everything works fine. but after installation of windows service it is created the processes of that windows application. but that windows application is not initiating..

My Service code is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;
using System.IO;
using System.Xml;

namespace OTMService
{
    public partial class OTMService : ServiceBase
    {
        private Timer timer1 = null;
        string tt1, tt2, tt3, tt4, tt5, tt6, thetime, time, tmp1, tmp0ch, basetmp, tmpAMPM;
        int spp = 0, stime = 0;
        public OTMService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            timer1 = new Timer();
            this.timer1.Interval = 60000; //for every 30 secs=30000 and for 1 minute 60000 and 300000
            this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
            timer1.Enabled = true;
            Library.WriteErrorLog("Test window service started--Just Khan");
        }

        private void timer1_Tick(object sender, ElapsedEventArgs e)
        {
            mymainProg();
        }
        protected override void OnStop()
        {
            timer1.Enabled = false;
            Library.WriteErrorLog("Test window service stopped--Just Khan-Service got stopped");
        }
        public void mymainProg()
        {
            string dirpath = AppDomain.CurrentDomain.BaseDirectory;
            //xml reading for getting time mentioned in xml file.
            try
            {
                XmlDocument xmlDoc1 = new XmlDocument();
                xmlDoc1.Load(dirpath+"OTMAppSetting.xml");
                thetime = xmlDoc1.SelectSingleNode("Data/ServTime").InnerText;
                //thetime = "02:04 PM";
                tmp1 = thetime.Substring(3, 2);
                tmp0ch = thetime.Substring(3, 1);
                basetmp = thetime.Substring(0, 3);
                tmpAMPM = thetime.Substring(6, 2);
                spp = Convert.ToInt32(tmp1);
                stime = checktime(spp);
                if(tmp0ch=="0")
                {
                    tt1 = basetmp + "0"+ stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt2 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt3 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt4 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt5 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt6 = basetmp + "0" + stime.ToString() + " " + tmpAMPM;
                }
                else
                {
                    tt1 = basetmp + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt2 = basetmp + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt3 = basetmp + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt4 = basetmp + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt5 = basetmp + stime.ToString() + " " + tmpAMPM;
                    stime = stime + 1;
                    tt6 = basetmp + stime.ToString() + " " + tmpAMPM;
                }
                
            }
            catch (Exception g)
            {
                Library.WriteErrorLog("Xml loading error for time: Error" + g.ToString());
            }
            //Write code here to do some job depends on your requirement
            DateTime dt = DateTime.Now;
            time = dt.ToString("hh:mm tt");
            /*if (time == "02:49 PM" || time == "02:52 PM" || 
                time == "02:56 PM" || time == "02:57 PM" || 
                time == "02:58 PM" || time == "02:59 PM")*/
            if (time == tt1 || time == tt2 ||
                time == tt3 || time == tt4 ||
                time == tt5 || time == tt6)
            {
                //Library.WriteErrorLog("Timer ticked now inside time... and some job has been done successfully--JustKhan-Job Initiated :");
                try
                {
                    Library.WriteErrorLog("Inside time and under try and catch Before Using");
                    //killing already existing process....
                    foreach (var process in Process.GetProcessesByName("OTMBackendServiceExe"))
                    {
                        process.Kill();
                    }
                    //-------------killing completed...
                    using (Process pp = Process.Start(dirpath + "OTM_Plan_BackExe\\OTMBackendServiceExe.exe"))
                    {
                        int id = pp.Id;
                        //Library.WriteErrorLog("Process iD: "+id.ToString());
                        //Library.WriteErrorLog("Process Name: " + pp.ProcessName.ToString());
                        Process tempProc = Process.GetProcessById(id);
                        //tempProc.WaitForExit(60000);
                        //tempProc.WaitForExit();
                        Library.WriteErrorLog("Process completed all");
                    }
                }
                catch (Exception ex)
                {
                    Library.WriteErrorLog("Main Exe cannot be started: " + ex.ToString());
                }

            }
        }

        private int checktime(int ss)
        {
            int theret = 0;
            switch (ss)
            {
                case 54:
                    theret = ss - 2;
                    break;
                case 55:
                    theret = ss - 3;
                    break;
                case 56:
                    theret = ss - 4;
                    break;
                case 57:
                    theret = ss - 5;
                    break;
                case 58:
                    theret = ss - 6;
                    break;
                case 59:
                    theret = ss - 6;
                    break;
                default:
                    theret = ss;
                    break;
            }
            return theret;
        }
    }
}


and the windows application starting code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using Oracle.DataAccess.Client;
using Excel = Microsoft.Office.Interop.Excel;
using System.Net.Mail;

namespace OTMBackendServiceExe
{
    public partial class Form1 : Form
    {
        string oraCstr, qrystr, qrystr1, OraCon, malstatus;
        bool chk1 = false, chk2 = false;
        int lcount = 0, chkkedd=0;
        string empname, email_id, sup_email, cc_maillst, fcc_maillst, skilltype, product, skilltrack, current_level, target_level, tomail_sub;
        string mailfor, otmmailbody, mail_sent_date, mail_sent_status, mailerr_msg;
        string repformpath, repoutputpath, repfilename;
        StringBuilder mlmsg = new StringBuilder();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            WriteToFile("Testing: App Started");
            XmlDocument xmlDoc = new XmlDocument();
            //xmlDoc.Load("d:\\product.xml");
            xmlDoc.Load("OTMAppSetting.xml");
            //string id = xmlDoc.SelectSingleNode("Data/Short_Fall").InnerText;
            oraCstr = "";
            oraCstr = xmlDoc.SelectSingleNode("Data/DBstr").InnerText;
            frommail = xmlDoc.SelectSingleNode("Data/frommmail").InnerText;
            cc_maillst = xmlDoc.SelectSingleNode("Data/ccmaillst").InnerText;
            WriteToFile("Started @:"+DateTime.Now.ToString());
            //--------------------------------------
            //-----these are for checking purpose------------
            //dbcheck();
            //string dd = mailcheck();
            //WriteToFile("MailStatus :" + dd);
            //To Enable from here...
            //--------------------------------------
            nightqry();
            allresettings();
            skillupgrademail();
            //--------------------------------------
            //all functions End here.....
            WriteToFile("Ended @:" + DateTime.Now.ToString());
            Application.Exit();
            //this.Close();
        }

in task manager it shows the process of that backend exe.



Need help. this backend exe is not getting executed when i run through service. if i run directly without any problem it runs.
Khan

AnswerRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 2:41
mveOriginalGriff1-Jan-18 2:41 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 3:15
Mohiyuddin Khan1-Jan-18 3:15 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 3:37
mveOriginalGriff1-Jan-18 3:37 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 3:50
Mohiyuddin Khan1-Jan-18 3:50 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 4:19
mveOriginalGriff1-Jan-18 4:19 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 18:16
Mohiyuddin Khan1-Jan-18 18:16 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 23:16
Mohiyuddin Khan1-Jan-18 23:16 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
OriginalGriff1-Jan-18 23:31
mveOriginalGriff1-Jan-18 23:31 
AnswerRe: struck in launching .exe file created using c# using windows service. Pin
jschell1-Jan-18 6:45
jschell1-Jan-18 6:45 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
Mohiyuddin Khan1-Jan-18 20:20
Mohiyuddin Khan1-Jan-18 20:20 
GeneralRe: struck in launching .exe file created using c# using windows service. Pin
jschell3-Jan-18 13:05
jschell3-Jan-18 13:05 
AnswerRe: struck in launching .exe file created using c# using windows service. Pin
Gerry Schmitz1-Jan-18 7:42
mveGerry Schmitz1-Jan-18 7:42 
QuestionDo you know any good unit testing and mocking frameworks for C#? Pin
JamesRichmond31-Dec-17 23:49
JamesRichmond31-Dec-17 23:49 
AnswerRe: Do you know any good unit testing and mocking frameworks for C#? Pin
jschell1-Jan-18 6:48
jschell1-Jan-18 6:48 
AnswerRe: Do you know any good unit testing and mocking frameworks for C#? Pin
Pete O'Hanlon1-Jan-18 9:29
subeditorPete O'Hanlon1-Jan-18 9:29 
AnswerRe: Do you know any good unit testing and mocking frameworks for C#? Pin
Alex Schunk8-Jan-18 7:10
Alex Schunk8-Jan-18 7:10 
Questiondownload pdf from pdfdrive.net Pin
Arnav Das31-Dec-17 20:38
Arnav Das31-Dec-17 20:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.