Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Adobe Reader process fails when starting second instance -


in our c# winforms application, generate pdf files , launch adobe reader (or whatever default system .pdf handler is) via process class. since our pdf files can large (approx 200k), handle exited event clean temp file afterwards.

the system works required when file opened , closed again. however, when second file opened (before closing adobe reader) second process exits (since reader using it's mdi powers) , in our exited handler our file.delete call should fail because it's locked joined adobe process. however, in reader instead get:

there error opening document. file cannot found.

the unusual thing if put debugger breakpoint before file deletion , allow attempt (and fail) deletion, system behaves expected!

i'm positive file exists , positive handles/file streams file closed before starting process.

we launching following code:

// open file viewing/printing (if default program supports it)  var pdfprocess = new process(); pdfprocess.startinfo.filename = tempfilename; if (pdfprocess.startinfo.verbs.contains("open", stringcomparer.invariantcultureignorecase)) {     var verb = pdfprocess.startinfo.verbs.first(v => v.equals("open", stringcomparison.invariantcultureignorecase));     pdfprocess.startinfo.verb = verb; } pdfprocess.startinfo.arguments = "/n"; // specifies new window used! (but not definitely...) pdfprocess.synchronizingobject = this; pdfprocess.enableraisingevents = true; pdfprocess.exited += new eventhandler(pdfprocess_exited);  _pdfprocessdictionary.add(pdfprocess, tempfilename);  pdfprocess.start(); 

note: using _pdfprocessdictionary store references process objects stay in scope exited event can raised.

our cleanup/exited event is:

void pdfprocess_exited(object sender, eventargs e) {     debug.assert(!invokerequired);     var p = sender process;     try     {         if (_pdfprocessdictionary.containskey(p))         {             var tempfilename = _pdfprocessdictionary[p];             if (file.exists(tempfilename)) // how else can check if can delete it!!??             {                 // note: fail if adobe reader application instance has been re-used!                 file.delete(tempfilename);                 _pdfprocessdictionary.remove(p);             }              cleanotherfiles(); // function clean files other exited processes in our dictionary         }     }     catch (ioexception ex)     {         // swallow up, deal trying delete @ point     } } 

possible solutions:

  • detect file still open in process
  • detect second process hasn't been exited , file opened in first process instead

i just dealt couple of days ago.

when there no instance open already, document opens in new instance directly.

when there instance open, believe instance spawns new instance don't handle to. happens control returns function immediately, goes , deletes file before new instance has had chance read file -- hence appears not there.

i "solved" not deleting files immediately, keeping track of paths in list, , nuking of them when program exits (wrap each delete in try/catch empty catch block in case file has disappeared in meantime).


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -