Re: [genexusextensions] Cross-thread operation not valid: Control 'DocumentMdiView' accessed from a thread other than the thread it was created on.

Senhores,

Quais versões do Visual Studio suporta, abre os projetos de exemplo que vem dentro da pasta examples no SDK ?


Att



2012/12/3 Federico Azzato <fazzato@genexus.com>
Hola Enrique

El código que ejecuta al momento de asignar el valor Dirty, cambió de ev1 a ev2.  El cambio que se hizo fue justamente actualizar el icono del objeto cuando cambia de estado (de dirty a no dirty, o viceversa) para reflejar mejor cambios internos que podían afectar el icono que se muestra.

Hasta el momento el cambio de estado se venía ejecutando en el propio thread de UI, por lo que no había saltado este problema. El problema ocurre cuando el cambio de estado se hace desde un thread en background. Lo vamos a corregir, pero mientras tanto, para evitar el problema, puede hacer lo siguiente:


if (UIServices.DocumentManager.IsOpenDocument(obj, out document))
{
document.Object.AddCategory(catUnreachables);
SetDocumentDirty(document);
UIServices.TrackSelection.OnSelectChange(document.Object, null);
}

Y luego implementar SetDocumentDirty de la siguiente forma:

private void SetDocumentDirty(IGxDocument doc)
{
if (UIServices.Environment.InvokeRequired) // devuelve true cuando el thread que está ejecutando no es el thread de UI
UIServices.Environment.BeginInvoke(() => SetDocumentDirty(doc)); // dispara un invoke asincrónico a SetDocumentDirty
else
doc.Dirty = true;
}

Saludos

Federico Azzato

Development & Research


On Sun, Dec 2, 2012 at 8:00 PM, Enrique Almeida <enrique.almeida@gmail.com> wrote:
Estoy procesando objetos con una extension y hago:


                Artech.Architecture.UI.Framework.Objects.IGxDocument document;
                if (UIServices.DocumentManager.IsOpenDocument(obj, out document))
                {
                    document.Object.AddCategory(catUnreachables);
                    document.Dirty = true;
                    UIServices.TrackSelection.OnSelectChange(document.Object, null);
                }

para marcar los objetos abiertos como cambiados. Esto funcionaba en versiones anteriores, pero ahora da el error:

System.InvalidOperationException was unhandled
  Message=Cross-thread operation not valid: Control 'DocumentMdiView' accessed from a thread other than the thread it was created on.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, IntPtr lparam)
       at System.Windows.Forms.Form.UpdateWindowIcon(Boolean redrawFrame)
       at System.Windows.Forms.Form.set_Icon(Icon value)
       at Artech.Core.UI.Documents.DocumentMdiView.Document_DocumentDirtyChanged(Object sender, DocumentEventArgs args)
       at Artech.Core.UI.Documents.GxDocument.OnDocumentStatusChanged()
       at Artech.Core.UI.Documents.GxDocument.set_Dirty(Boolean value)
       at Concepto.Packages.KBDoctor.ObjectsHelper.Unreachables() in C:\Models\vs2010\GXExtensions\gxextensions\trunk\KBDoctor\ObjectsHelper.cs:line 82
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

Como evito este error? 




--
Bruno Vrban Aquino
GeneXus Senior Systems Analyst

http://www.vrban.com.br             55 71 3024-5810      
bruno@vrban.com.br                  55 71 9285-2180  




    

--
 
 

0 Response to "Re: [genexusextensions] Cross-thread operation not valid: Control 'DocumentMdiView' accessed from a thread other than the thread it was created on."

Publicar un comentario