none
Object sharing between thread : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RRS feed

  • Question

  • Hi,

    Iam working on a Visual studio2012 plugin development using Visual studio SDK 2012. Iam getting an error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." My application has one UI thread and one child thread. The same project executes well in VS2010.

    For example,

    In the below model code while accessing  Class1.Method2() from child thread iam getting an error.

    Class CustomProjectNode: Project Node{

    Class1 class1Obj =new Class1();

    class1Obj .Method1(this);

    }

    Class Class1

    {

    CustomProjectNode customProjectNode;

    Method1(CustomProjectNode customProjectNode)

    {

    this.customProjectNode=customProjectNode;

    WindowsForm  windFormObj=new WindowsForm(this); 

    }

    Public void Method2()

    {

    this.customProjectNode.SomeMethod();

    }

    }

    WindowsForm:Form  

    {

     

    WindowsForm(Class1 class1Obj)

    {

    Thread threobj=new Thread(class1Obj.Method2);

    threobj.start();

    }

    }

    I could not use this.Invoke((MethodInvoker)delegate. Since my child thread code is not related to UI control class.

    Kindly could you help me to resolve this issue.

     

    Thanks & Regards,

    Ellaiyaraja.B

     


    Thanks & Regards, Ellaiyaraja B

    Tuesday, May 21, 2013 7:47 PM

Answers

  • I'm wondering if the STAThread is missing in the 2012 project.  Depending on the project you are using sometimes VS will automatically create the STAThread in the program.cs file or in th edesigner file for a form.  it could be the reason why the code works in 2010.

       [STAThread]
       
    static void Main(string[] args)
         
    {


    jdweng

    Tuesday, May 21, 2013 11:56 PM