c# - Dispatcher.Run generates Win32Exception only when application is run as published application in RDS -


i have legacy modal dialog need present windows wpf/c# application. works under specific circumstance of published application in rds if user waits few minutes between main application , invoking dialog crash rather cryptic error.

i know how list of messages dispatcher running: if analyse messages being processed have shot @ understanding underlying problem.

the actual exception win32exception. message "the system cannot find file specified". hresult x80004005.

the complete error text is:

system.componentmodel.win32exception (0x80004005): system cannot find file specified @ ms.win32.unsafenativemethods.getwindowtext(handleref hwnd, stringbuilder lpstring, int32 nmaxcount) @ system.windows.automation.peers.windowautomationpeer.getnamecore() @ system.windows.automation.peers.automationpeer.updatesubtree() @ system.windows.automation.peers.automationpeer.updatepeer(object arg) @ system.windows.threading.exceptionwrapper.internalrealcall(delegate callback, object args, int32 numargs) @ ms.internal.threading.exceptionfilterhelper.trycatchwhen(object source, delegate method, object args, int32 numargs, delegate catchhandler) @ system.windows.threading.dispatcheroperation.invokeimpl() @ system.windows.threading.dispatcheroperation.invokeinsecuritycontext(object state) @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean preservesyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.windows.threading.dispatcheroperation.invoke() @ system.windows.threading.dispatcher.processqueue() @ system.windows.threading.dispatcher.wndprochook(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndwrapper.wndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndsubclass.disp 

i have put break points @ places gets window text hasn't yielded useful.

the actual legacy thread here:

public void initlegacythread(string config, string username, string userpswd, double userloc) {     _legacythread = new thread(() =>     {         try         {             application app = new application();             app.resources.mergeddictionaries.add(new resourcedictionary { source = new uri(xamlresourceslocation, urikind.relative) });             clientservicelocator.getinstance<ilegacymldispatchthread>().initialize(dispatcher.currentdispatcher);             if (thread.currentthread.threadstate != threadstate.aborted)             {                 thread.currentthread.priority = threadpriority.belownormal;             }             registerappservicesandevents();             _initializationsuccessful = serviceprovider.instance.getservice<iinteropadapter>().finishinitializing(config, username, userpswd, userloc);              if (_initializationsuccessful)             {                 bringpopupdialogstofront();                 clientservicelocator.getinstance<ieventaggregator>().subscribe(this);                 initializecommonshellwindow();                 createbindings();                  if (thread.currentthread.threadstate != threadstate.aborted)                 {                     thread.currentthread.priority = threadpriority.normal;                 }                  // signal legacy thread ready                 clientservicelocator.getinstance<ilegacymldispatchthread>().signalthreadready();                  try                 {                     dispatcher.run();                 }                 catch (win32exception e)                 {                     exceptionhandler.showexception(e, e.message);                 }             }             else             {                 abortinitialization();                  try                 {                     dispatcher.run();                 }                 catch (win32exception e)                 {                     exceptionhandler.showexception(e, e.message);                 }             }         }         catch (exception e)         {             exceptionhandler.showexception(e, e.message);         }     });     _legacythread.setapartmentstate(apartmentstate.sta);     _legacythread.name = mlthreadname;     _legacythread.start(); } 

the answer 1 can using dispatcherhookeventhandler , hwndsourcehook. messages processed dispatcher sdk type windows messages not 1 one correspondence had hoped be. however, 1 can point adding hook on target window.

    public static intptr messagereader(intptr hwnd, int message, intptr lparam, intptr wparam, ref bool result)     {         _log.error(string.format("messagereader - {0}, {1}, {2}, {3}", hwnd, message, lparam, wparam));         return intptr.zero;     }     public static intptr messagereader(intptr hwnd, int message, intptr lparam, intptr wparam, ref bool result)     ....         fieldinfo argsfield = typeof(dispatcheroperation).getfield("_args", bindingflags.nonpublic | bindingflags.instance);         dispatcher.currentdispatcher.hooks.operationstarted += new dispatcherhookeventhandler((obj, args) =>         {             system.windows.interop.hwndsource source = argsfield.getvalue(args.operation) system.windows.interop.hwndsource;             if (source != null)             {                 source.addhook(new system.windows.interop.hwndsourcehook(messagereader));             }         });         dispatcher.run(); 

this strictly finding out window message contributing particular issue. in way 1 can @ sdk type messages before processed in wpf application.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -