Click here to Skip to main content
15,886,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: Threading - Play / pause / stop question Pin
Pete O'Hanlon14-Nov-13 2:28
mvePete O'Hanlon14-Nov-13 2:28 
GeneralRe: Threading - Play / pause / stop question Pin
Mirko Jurcevic14-Nov-13 2:33
Mirko Jurcevic14-Nov-13 2:33 
GeneralRe: Threading - Play / pause / stop question Pin
Pete O'Hanlon14-Nov-13 3:02
mvePete O'Hanlon14-Nov-13 3:02 
AnswerRe: Threading - Play / pause / stop question Pin
Ennis Ray Lynch, Jr.14-Nov-13 5:41
Ennis Ray Lynch, Jr.14-Nov-13 5:41 
QuestionConvert Datatable data into Json data in C# Pin
susanna.floora14-Nov-13 1:12
susanna.floora14-Nov-13 1:12 
AnswerRe: Convert Datatable data into Json data in C# Pin
V.14-Nov-13 2:04
professionalV.14-Nov-13 2:04 
AnswerRe: Convert Datatable data into Json data in C# Pin
Richard Deeming14-Nov-13 4:19
mveRichard Deeming14-Nov-13 4:19 
Question[Solved] Windows Service - problem with write file at scheduled time Pin
emma.sun.sts13-Nov-13 20:06
emma.sun.sts13-Nov-13 20:06 
Hi,

I'm quite new to C# and been working on this problem for days and already at my dead end Frown | :( . I have been trying to learn from sample codes from forums and doing lots of cuts and pastes. Hope someone can help.

I have a Windows Service where I am getting data from web, write it to a .txt file and email at scheduled time.

I can send scheduled email alone. But when I tried to extract data from web, write that data in .txt file and email that data as scheduled altogether, the program hangs at new StreamWriter declaration. I used eventLog1.WriteEntry() to check where it stops. There is no error message. The program just hangs there. I really don't know what is happening. Can someone help? This is what I have done so far ..

protected override void OnStart(string[] args) 
        {            
            System.Timers.Timer time = new System.Timers.Timer();
            time.Start();
            time.Interval = (1000 * 60 * 5); //5 minutes
            time.Elapsed += new ElapsedEventHandler(time_elapsed);
            time.AutoReset = true;
            time.Start();            
        }
        
        public void time_elapsed(object sender, ElapsedEventArgs e)
        {
            DateTime scheduledRun = DateTime.Today.AddHours(13.20);    
            DateTime lastRan = lastTime.LastWriteTime;
            if (DateTime.Now > scheduledRun)
            {
                TimeSpan sinceLastRun = DateTime.Now - lastRan;
                if (sinceLastRun.Minutes > 5)
                {
                    importFrmURL("http:// ..", "@"\Import1.txt"");                    
                }
            }
        }

 public void importFrmURL(string url, string dir) // dir = @"\Import1.txt"
 {
 System.IO.StreamWriter fileWriter;
 fileWriter = new System.IO.StreamWriter(dir); //<---PROBLEM------ hang there
 try
 { 
 var client = new WebClient();
 using (var stream = client.OpenRead(url)) 
 using (var reader = new StreamReader(stream))
 {
 string line;
 while ((line = reader.ReadLine()) != null)
 {
 fileWriter.WriteLine(line);
 }
 fileWriter.Close();
 }//---------------------------------------------------------------------------------
 }
 catch (Exception e)
 {
 eventLog1.WriteEntry("Error occurred!\n\r" + e.ToString());//<---DEBUG
 } 
 }


modified 28-Nov-13 2:28am.

AnswerRe: Windows Service - problem with write file at scheduled time Pin
Bernhard Hiller13-Nov-13 20:56
Bernhard Hiller13-Nov-13 20:56 
GeneralRe: Windows Service - problem with write file at scheduled time Pin
emma.sun.sts13-Nov-13 21:25
emma.sun.sts13-Nov-13 21:25 
GeneralRe: Windows Service - problem with write file at scheduled time Pin
Bernhard Hiller13-Nov-13 21:29
Bernhard Hiller13-Nov-13 21:29 
GeneralRe: Windows Service - problem with write file at scheduled time Pin
emma.sun.sts13-Nov-13 21:39
emma.sun.sts13-Nov-13 21:39 
GeneralRe: Windows Service - problem with write file at scheduled time Pin
Eddy Vluggen13-Nov-13 21:48
professionalEddy Vluggen13-Nov-13 21:48 
GeneralRe: Windows Service - problem with write file at scheduled time Pin
Pete O'Hanlon14-Nov-13 0:14
mvePete O'Hanlon14-Nov-13 0:14 
Questionread only Pin
seeker6213-Nov-13 8:41
seeker6213-Nov-13 8:41 
SuggestionRe: read only Pin
Richard MacCutchan13-Nov-13 8:56
mveRichard MacCutchan13-Nov-13 8:56 
GeneralRe: read only Pin
seeker6213-Nov-13 9:13
seeker6213-Nov-13 9:13 
GeneralRe: read only Pin
Richard MacCutchan13-Nov-13 9:29
mveRichard MacCutchan13-Nov-13 9:29 
GeneralRe: read only Pin
seeker6213-Nov-13 9:47
seeker6213-Nov-13 9:47 
GeneralRe: read only Pin
Richard MacCutchan13-Nov-13 10:42
mveRichard MacCutchan13-Nov-13 10:42 
GeneralRe: read only Pin
seeker6213-Nov-13 10:49
seeker6213-Nov-13 10:49 
GeneralRe: read only Pin
Richard MacCutchan13-Nov-13 10:57
mveRichard MacCutchan13-Nov-13 10:57 
GeneralRe: read only Pin
Ron Nicholson14-Nov-13 3:24
professionalRon Nicholson14-Nov-13 3:24 
GeneralRe: read only Pin
Nicholas Marty15-Nov-13 4:49
professionalNicholas Marty15-Nov-13 4:49 
AnswerThe system cannot find the file specified for process.start(). Pin
subhendun dan13-Nov-13 4:53
subhendun dan13-Nov-13 4:53 

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.