P
pbd22
Hi.
I am stuck on a part of my program and could use some help.
I have a block of code that opens and writes to a text file.
The idea is to keep the file open and keep writing to it until
the EndOfStream event is fired.
My project is a carry-over from a VB6 project and the Extractor()
classes comes with a number of events for this particular part of
the program. The ones of note are the DataEventHandler that
keeps writing data to the text file until the EndOfStreamEventHandler
is fired.
I am not too strong in delegates and event handlers and I would
really
appreciate some guidance as to how to use these two event handlers
to loop, creating more text, until the end of stream is reached.
Below is what I have so far but this doesn't work (I get an empty
file):
private static void Test()
{
data = new Extractor();
data.OnData += new _DataEventHandler(data_Data);
data.EndOfStream += new
_EndOfStreamEventHandler(data_EndOfStream);
using (sw =
System.IO.File.CreateText(videofile.Replace(".mpg", ".txt")))
{
data_Data(strTimeCC, strCC);
}
}
void data_Data(string strTime, string strText)
{
try
{
sw.WriteLine(strTime + Constants.vbTab +
strText.Replace("<br>", " "));
sw.Flush();
}
catch
{
throw new Exception("The method or operation
data_OnCCData is not implemented.");
}
}
void data_EndOfStream()
{
try
{
sw.WriteLine(" ");
sw.Close();
}
catch
{
throw new Exception("The method or operation
data_EndOfStream() is not implemented.");
}
}
I am stuck on a part of my program and could use some help.
I have a block of code that opens and writes to a text file.
The idea is to keep the file open and keep writing to it until
the EndOfStream event is fired.
My project is a carry-over from a VB6 project and the Extractor()
classes comes with a number of events for this particular part of
the program. The ones of note are the DataEventHandler that
keeps writing data to the text file until the EndOfStreamEventHandler
is fired.
I am not too strong in delegates and event handlers and I would
really
appreciate some guidance as to how to use these two event handlers
to loop, creating more text, until the end of stream is reached.
Below is what I have so far but this doesn't work (I get an empty
file):
private static void Test()
{
data = new Extractor();
data.OnData += new _DataEventHandler(data_Data);
data.EndOfStream += new
_EndOfStreamEventHandler(data_EndOfStream);
using (sw =
System.IO.File.CreateText(videofile.Replace(".mpg", ".txt")))
{
data_Data(strTimeCC, strCC);
}
}
void data_Data(string strTime, string strText)
{
try
{
sw.WriteLine(strTime + Constants.vbTab +
strText.Replace("<br>", " "));
sw.Flush();
}
catch
{
throw new Exception("The method or operation
data_OnCCData is not implemented.");
}
}
void data_EndOfStream()
{
try
{
sw.WriteLine(" ");
sw.Close();
}
catch
{
throw new Exception("The method or operation
data_EndOfStream() is not implemented.");
}
}