N
null
I have a web application that fires off an async task, but I have not been able
to determine if there is a way for my application to notify the user that the
task has finished.
Here are the relevant parts of the code:
public partial class default2 : System.Web.UI.Page
{
#region struct to pass data to AsyncCallback method
public struct EncoderData
{
public IFlix flxFlix;
public string strSavePath;
public DateTime dtStartTime;
public string strOutputVideo;
public int intWidth;
public int intHeight;
public EncoderData(IFlix flxIn, string strPathIn, DateTime dtStartIn,
string strOutVidIn, int intWidthIn, int intHeightIn)
{
flxFlix = flxIn;
strSavePath = strPathIn;
dtStartTime = dtStartIn;
strOutputVideo = strOutVidIn;
intWidth = intWidthIn;
intHeight = intHeightIn;
}
}
#endregion struct to pass data to AsyncCallback method
public delegate void AsyncCaller(EncoderData myEncoderData);
AsyncCaller acEncoderCaller = new AsyncCaller(RunEncoder);
[MTAThread]
protected void btnEncode_Click(object sender, EventArgs e)
{
DateTime startTime;
string savePath = @"C:\_testData\flixmedia\temp\";
/* create an instance of the main engine interface, IFlix */
IFlix flix = (IFlix)createInstance("On2.FlixEngine");
lblMessage.Text = String.Empty;
#region invoke encoder
startTime = DateTime.Now;
EncoderData myEncoderData = new EncoderData(flix, savePath, startTime,
outputVideo, intOutputWidth, intOutPutHeight);
IAsyncResult arResult = acEncoderCaller.BeginInvoke(myEncoderData, new
AsyncCallback(EncodingDone), myEncoderData);
Session["EncoderResult"] = arResult;
#endregion invoke encoder
}
private static void RunEncoder(EncoderData encoderData)
{
// start the encode
flxRunEncoder.encode();
// retrieve the encoding status interface, IEncodingStatus
IEncodingStatus encstatus = flxRunEncoder.encodingStatus();
bool ier = true;
#region loop until encoder completion (check every 1 sec)
int intTime = 0;
while (ier)
{
ier = flxRunEncoder.isEncoderRunning() == 1;
System.Threading.Thread.Sleep(1000);
}
#endregion loop until encoder completion (check every 1 sec)
}
catch (COMException ex)
{
printStackTrace(flxRunEncoder, ex);
}
catch (Exception up)
{
ExceptionHandler.LogToTextFile( up.ToString());
}
}
private static void EncodingDone(IAsyncResult arIn)
{
try
{
EncoderData encoderData = (EncoderData)arIn.AsyncState;
IFlix flxEndEncode = encoderData.flxFlix;
DateTime startTime = encoderData.dtStartTime;
string savePath = encoderData.strSavePath;
printEncoderStatus(flxEndEncode);
DateTime stopTime = DateTime.Now;
TimeSpan duration = stopTime - startTime;
#region end the encoder process invocation
AsyncResult ar = (AsyncResult)arIn;
AsyncCaller myAsyncDelegate = (AsyncCaller)ar.AsyncDelegate;
myAsyncDelegate.EndInvoke(ar);
#endregion end the encoder process invocation
#region delete temp file
try
{
File.Delete(savePath);
}
catch (Exception up)
{
ExceptionHandler.LogToTextFile( "Encoding complete, but cleanup of
temp file failed. Error = " + up.ToString());
}
#endregion delete temp file
}
catch (System.Exception up)
{
ExceptionHandler.LogToTextFile(up.ToString());
}
}
to determine if there is a way for my application to notify the user that the
task has finished.
Here are the relevant parts of the code:
public partial class default2 : System.Web.UI.Page
{
#region struct to pass data to AsyncCallback method
public struct EncoderData
{
public IFlix flxFlix;
public string strSavePath;
public DateTime dtStartTime;
public string strOutputVideo;
public int intWidth;
public int intHeight;
public EncoderData(IFlix flxIn, string strPathIn, DateTime dtStartIn,
string strOutVidIn, int intWidthIn, int intHeightIn)
{
flxFlix = flxIn;
strSavePath = strPathIn;
dtStartTime = dtStartIn;
strOutputVideo = strOutVidIn;
intWidth = intWidthIn;
intHeight = intHeightIn;
}
}
#endregion struct to pass data to AsyncCallback method
public delegate void AsyncCaller(EncoderData myEncoderData);
AsyncCaller acEncoderCaller = new AsyncCaller(RunEncoder);
[MTAThread]
protected void btnEncode_Click(object sender, EventArgs e)
{
DateTime startTime;
string savePath = @"C:\_testData\flixmedia\temp\";
/* create an instance of the main engine interface, IFlix */
IFlix flix = (IFlix)createInstance("On2.FlixEngine");
lblMessage.Text = String.Empty;
#region invoke encoder
startTime = DateTime.Now;
EncoderData myEncoderData = new EncoderData(flix, savePath, startTime,
outputVideo, intOutputWidth, intOutPutHeight);
IAsyncResult arResult = acEncoderCaller.BeginInvoke(myEncoderData, new
AsyncCallback(EncodingDone), myEncoderData);
Session["EncoderResult"] = arResult;
#endregion invoke encoder
}
private static void RunEncoder(EncoderData encoderData)
{
// start the encode
flxRunEncoder.encode();
// retrieve the encoding status interface, IEncodingStatus
IEncodingStatus encstatus = flxRunEncoder.encodingStatus();
bool ier = true;
#region loop until encoder completion (check every 1 sec)
int intTime = 0;
while (ier)
{
ier = flxRunEncoder.isEncoderRunning() == 1;
System.Threading.Thread.Sleep(1000);
}
#endregion loop until encoder completion (check every 1 sec)
}
catch (COMException ex)
{
printStackTrace(flxRunEncoder, ex);
}
catch (Exception up)
{
ExceptionHandler.LogToTextFile( up.ToString());
}
}
private static void EncodingDone(IAsyncResult arIn)
{
try
{
EncoderData encoderData = (EncoderData)arIn.AsyncState;
IFlix flxEndEncode = encoderData.flxFlix;
DateTime startTime = encoderData.dtStartTime;
string savePath = encoderData.strSavePath;
printEncoderStatus(flxEndEncode);
DateTime stopTime = DateTime.Now;
TimeSpan duration = stopTime - startTime;
#region end the encoder process invocation
AsyncResult ar = (AsyncResult)arIn;
AsyncCaller myAsyncDelegate = (AsyncCaller)ar.AsyncDelegate;
myAsyncDelegate.EndInvoke(ar);
#endregion end the encoder process invocation
#region delete temp file
try
{
File.Delete(savePath);
}
catch (Exception up)
{
ExceptionHandler.LogToTextFile( "Encoding complete, but cleanup of
temp file failed. Error = " + up.ToString());
}
#endregion delete temp file
}
catch (System.Exception up)
{
ExceptionHandler.LogToTextFile(up.ToString());
}
}