FileWatcher/code/src/EventRaisingStreamWriter.cs

40 lines
903 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FileWatcher
{
public class EventRaisingStreamWriter : StreamWriter
{
public event EventHandler<MyEvtArgs<string>> StringWritten;
public EventRaisingStreamWriter(Stream s)
: base(s)
{
}
private void LaunchEvent(string txtWritten)
{
if (StringWritten != null)
{
StringWritten(this, new MyEvtArgs<string>(txtWritten));
}
}
public override void Write(string value)
{
base.Write(value);
LaunchEvent(value);
}
public override void Write(bool value)
{
base.Write(value);
LaunchEvent(value.ToString());
}
}
}