Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
QuestionIIS Media service question Pin
Rajan UNCC 15-Apr-10 10:42
Rajan UNCC 15-Apr-10 10:42 
QuestionFile Dialog Result Pin
mprice21415-Apr-10 9:38
mprice21415-Apr-10 9:38 
AnswerRe: File Dialog Result [modified] Pin
kevinnicol15-Apr-10 9:41
kevinnicol15-Apr-10 9:41 
AnswerRe: File Dialog Result Pin
PIEBALDconsult15-Apr-10 9:44
mvePIEBALDconsult15-Apr-10 9:44 
GeneralRe: File Dialog Result Pin
mprice21415-Apr-10 9:57
mprice21415-Apr-10 9:57 
AnswerRe: File Dialog Result Pin
Calla15-Apr-10 22:31
Calla15-Apr-10 22:31 
GeneralRe: File Dialog Result Pin
mprice21416-Apr-10 2:39
mprice21416-Apr-10 2:39 
QuestionAdding code to a method prevents previous code from executing? [modified] [SOLVED] Pin
Paladin200015-Apr-10 9:17
Paladin200015-Apr-10 9:17 
I am seeing some odd behavior in the timer_Elapsed method of a service that I am working on.
(It is an event handler for a System.Timers.Timer instance.)

If I remove the section of code marked "Detect and restore failed FSW objects", the call to "_log.Append" works fine (the _log is an instance of the Logging class described below). However, when that section is included, the "_log.Append" fails to operate. Is it possible that it can prevent the preceeding method call?
Also, everything works fine on Server 2003; this only misbehaves on Server 2008.

       /// <summary>
        /// The FileSystem watchers that monitor the specified folders.
        /// </summary>
        private List<FileSystemWatcher> _watchers = new List<FileSystemWatcher>();


        /// <summary>
        /// Automatic thread correction activity.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Event args.</param>
        private void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            _log.Append("Timer Cycle started.");

            //Detect and restore failed FSW objects
            try
            {
                if ((from w in _watchers where w.Path == _firewallDirectory.Source select w.Path).Count() == 0)
                {
                    FileSystemWatcher fw = new FileSystemWatcher(_firewallDirectory.Source);
                    fw.Created += new FileSystemEventHandler(fsw_Created);
                    fw.Renamed += new RenamedEventHandler(fsw_Renamed);
                    fw.EnableRaisingEvents = true;
                    _watchers.Add(fw);
                }
            }
            catch (Exception ex)
            {
                _log.Append("ERROR in Timer - FSW Restore: " + ex.Message);
            }
        }



*** FYI: Simple Flat-File Logging Class ***

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Logging
{
    /// <summary>
    /// Encapsulates logging features for the application.
    /// </summary>
    public class Log
    {
        #region Constructor

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="Path">The full file path for the log.</param>
        public Log(string Path)
        {
            _logStream = new StreamWriter(Path, true);
        }

        #endregion Constructor

        #region Private Properties

        /// <summary>
        /// The text stream for the file.
        /// </summary>
        private StreamWriter _logStream;

        #endregion Private Properties

        #region Public Methods

        /// <summary>
        /// Adds a new line to the end of the log file.
        /// </summary>
        /// <param name="LineToAdd">The text to add to the Log.</param>
        public void Append(string LineToAdd)
        {
            lock (_logStream)
            {
                _logStream.WriteLine(DateTime.Now.ToString() + "  " + LineToAdd);
                _logStream.Flush();
            }
        }

        #endregion Public Methods
    }
}

modified on Thursday, April 15, 2010 5:25 PM

AnswerRe: Adding code to a method prevents previous code from executing? [SOLVED] Pin
Paladin200015-Apr-10 11:25
Paladin200015-Apr-10 11:25 
QuestionDemand/LinkDemand Pin
Kevin Marois15-Apr-10 9:03
professionalKevin Marois15-Apr-10 9:03 
AnswerRe: Demand/LinkDemand Pin
Ravi Bhavnani15-Apr-10 17:21
professionalRavi Bhavnani15-Apr-10 17:21 
QuestionSimple C# logic traingle ?? Pin
Jaison V15-Apr-10 8:13
Jaison V15-Apr-10 8:13 
AnswerRe: Simple C# logic traingle ?? Pin
OriginalGriff15-Apr-10 8:28
mveOriginalGriff15-Apr-10 8:28 
AnswerRe: Simple C# logic traingle ?? Pin
PIEBALDconsult15-Apr-10 9:31
mvePIEBALDconsult15-Apr-10 9:31 
GeneralRe: Simple C# logic traingle ?? Pin
Jaison V15-Apr-10 10:40
Jaison V15-Apr-10 10:40 
AnswerRe: Simple C# logic traingle ?? Pin
Jaison V15-Apr-10 11:21
Jaison V15-Apr-10 11:21 
GeneralRe: Simple C# logic traingle ?? Pin
harold aptroot15-Apr-10 12:11
harold aptroot15-Apr-10 12:11 
AnswerRe: Simple C# logic traingle ?? Pin
Ravi Bhavnani15-Apr-10 17:24
professionalRavi Bhavnani15-Apr-10 17:24 
QuestionRecover deleted files!!! Pin
muteb15-Apr-10 7:22
muteb15-Apr-10 7:22 
AnswerRe: Recover deleted files!!! Pin
Dave Kreskowiak15-Apr-10 8:11
mveDave Kreskowiak15-Apr-10 8:11 
GeneralRe: Recover deleted files!!! Pin
muteb15-Apr-10 16:58
muteb15-Apr-10 16:58 
GeneralRe: Recover deleted files!!! Pin
Dave Kreskowiak15-Apr-10 17:53
mveDave Kreskowiak15-Apr-10 17:53 
GeneralRe: Recover deleted files!!! Pin
Jason Ingram16-Jun-10 13:25
Jason Ingram16-Jun-10 13:25 
GeneralRe: Recover deleted files!!! Pin
Dave Kreskowiak16-Jun-10 14:33
mveDave Kreskowiak16-Jun-10 14:33 
Questionhow could I make a set up for my Win App project that have database in sql server 2005? Pin
ronakT15-Apr-10 6:47
ronakT15-Apr-10 6:47 

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.