title: My Application closed by this Error : Attempted to read or write protected memory
body: <p>I have developed an application (using vs 2010 C#).
  After some time (1 hour or 3 or any ) my application is closed by this exception:
  <strong>Attempted to read or write protected memory. This is often an indication that other memory is corrupt</strong>.
  I don't know which part of my code causes this exception. What do I have to do?</p>
  
  <p>Note that I am using System.Data.SQLite dll and a dll (ocx file) from another software in my application and 5 Versions of this application is running simultaneously.</p>
  
  <blockquote>
  <pre><code>at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(MSG&amp; msg)
  at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
  at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  at System.Windows.Forms.Application.Run(Form mainForm)
  at IranAir.Program.Main() in C:\Users\Administrator\Desktop\Gabriel\Program.cs:line 18
  at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
  at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  at System.Threading.ThreadHelper.ThreadStart()
  </code></pre>
  </blockquote>
  
  <p>I have a com object in my application.it happens at the end of the one of its events.
  this com object has an event named Recieved_Message and after this event execute completely I got this error.</p>
  
  <pre><code> void a_Received(object sender, ReceivedEvent e)
  {
      //when processing finished successfully and it reachs to the close        bracket , this exception fired.
  }
  </code></pre>
  
  <p>so what is the problem?</p>