Note that there are some explanatory texts on larger screens.

plurals
  1. POWinforms: Attempted to read or write protected memory. This is often an indication that other memory is corrupt
    primarykey
    data
    text
    <p>I have a bunch of background events.</p> <p>All of them call a log:</p> <pre><code>private void log(string text, params object[] values) { if (editLog.InvokeRequired) { editLog.BeginInvoke( (MethodInvoker)delegate { this.log(text, values); }); } else { text = string.Format(text, values) + Environment.NewLine; lock (editLog) { editLog.AppendText(text); editLog.SelectionStart = editLog.TextLength; editLog.ScrollToCaret(); } } } </code></pre> <p>Sometimes I get this, but other times not:</p> <pre><code>System.AccessViolationException was unhandled Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message&amp; m) at System.Windows.Forms.Control.WndProc(Message&amp; m) at System.Windows.Forms.RichTextBox.WndProc(Message&amp; m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Object&amp; editOle) at System.Windows.Forms.TextBoxBase.ScrollToCaret() at Program1.frmMain.log(String text, Object[] values) in ... ... ... </code></pre> <p>P.D: Not always stop at this line, randomly will be one of the three times editLog methods/properties are used. Not always a exception is throw. Sometimes look like the thing freeze. But not the main UI, just the flow of messages (ie: log look like is never called again)</p> <p>The app is a single form, with background process. I can't see what I doing wrong with this...</p> <p><strong>UPDATE</strong>:</p> <p>I do the suggestion of Mangist, this is the code (the timer fire at 100ms). Same result:</p> <pre><code>private Queue&lt;String&gt; logs = new Queue&lt;String&gt;(); private void timerLog_Tick(object sender, EventArgs e) { lock (logs) { for (int i = 0; i &lt; logs.Count; i++) { editLog.AppendText(logs.Dequeue()); editLog.SelectionStart = editLog.TextLength; editLog.ScrollToCaret(); } } } private void log(string text, params object[] values) { text = string.Format(text, values) + Environment.NewLine; if (editLog.InvokeRequired) { editLog.BeginInvoke( (MethodInvoker)delegate { lock (logs) { logs.Enqueue(text); } //this.log(text, values); }); } else { logs.Enqueue(text); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload