flash - How to abort a C# console app after a set timeout -
we have application developed 3rd party organization in circumstances hang without exiting gracefully.
here's summary of application: takes in video, swf, image ...really media , capture thumbnail @ specific frame or after specified duration , output thumbail specified directory.
i'm looking way set timeout on function captures screen shots flash videos dispose form, flash control , exit app if timeout has exceeded. put timer or stopwatch in app , periodically check if time specified had exceeded doesnt seem eligant solution. there has better way.
heres function (its not pretty):
static void thumbnailforswf( string inputfile, string outputfile, int32 w, int32 h, float? time, float? quality ) { axshockwaveflashobjects.axshockwaveflash flash = new axshockwaveflashobjects.axshockwaveflash(); flash.location = new system.drawing.point( 0, 0 ); flash.clientsize = new size( w, h ); flash.enabled = true; flash.fscommand += ( object sender, axshockwaveflashobjects._ishockwaveflashevents_fscommandevent e ) => { switch( e.command ) { case "trace": console.writeline( e.args ); break; case "error": console.writeline( e.args ); ( (form)( (control)sender ).parent ).close(); break; case "data": byte[] data = convert.frombase64string( e.args ); using( filestream fs = file.open( outputfile, filemode.create, fileaccess.write ) ) { fs.write( data, 0, data.length ); } break; case "done": ( (form)( (control)sender ).parent ).close(); break; } }; form form = new form(); form.formborderstyle = formborderstyle.none; form.showintaskbar = false; form.load += ( object sender, eventargs e ) => { ( (form)sender ).visible = false; ( (form)sender ).clientsize = new size( 0, 0 ); try { flash.allownetworking = "all"; flash.allowscriptaccess = "always"; flash.wmode = "window"; flash.flashvars = string.format( "width={0}&height={1}&time={2}&quality={3}&input={4}", w, h, time ?? 0, quality ?? 80, inputfile ); flash.movie = path.combine( assemblydirectory, "flashthumbnail.swf" ); } catch( exception ex ) { console.writeline( ex.message ); ( (form)sender ).close(); } }; form.controls.add( flash ); flash.createcontrol(); application.run( form ); }
you need start function task , can monitor task duration using stopwath , if elapsed reaches number terminate task
Comments
Post a Comment