i did put this code in the “TextChanged”-event, but i think it's 'too late' there:
Private void textTiteUltTest_TextChanged(object sender, EventArgs e) {
TextBox tb = (TextBox)sender;
DataLayer DBClass = new DataLayer();
try {
string SQL = ;
string strVar = textTiteUltTest.Text + "%";
//Get SqlDataReader from DataClass
SqlDataReader sqlDR = DBClass.ReturnDataReader(SQL, , strVar);
AutoCompleteStringCollection autoCol = new AutoCompleteStringCollection();
//fill stringcollection
while (sqlDR.Read()) {
autoCol.Add(sqlDR["TITE_TITLES"].ToString());
}
//fill autocomplete textbox
lock (tb.AutoCompleteCustomSource.SyncRoot) {
tb.AutoCompleteCustomSource = autoCol;
}
}
catch (Exception exc) {
Console.WriteLine(exc.Data.ToString() + exc.Message.ToString());
}
finally {
//cleanup
DBClass.Dispose();
Console.WriteLine("'textTiteUltTest_TextChanged'");
}
}
error -> AccessViolationException:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Data: {System.Collections.ListDictionaryInternal}
not in the try/catch-block, but here:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
So i think, while i'm typing into the textbox the code from TextChangded-event is filling the autocomplete-stringcollection in one thread and the internal textbox-method/function needs to read from the autocomplete-stringcollection at the same time in a different thread.
The locking of SyncRoot doesn’t help at all, but I’m not even sure if I made it right in this case.
Also i have to say that this code sometimes works and sometimes it crashes. i think it depends on the speed of getting the sql server resultset.
so is this possiable ?
i am also go through this link1 and link2 but they not answer yet so please help to solve out this
The Exact Error I am getting is this: System.AccessViolationException Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Stack trace for error System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch) at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch) at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e) at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) at System.Windows.Forms.Control.ProcessKeyMessage(Message& m) at System.Windows.Forms.Control.WmKeyChar(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.RichTextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)