So I import the engine as a dll into a standard forms application and then place the SlimDX window inside a scrollable panel.
As part of my testing I am using a KeyUp event to load some textures and display them on some quads. But something strange is happening if I tap the key very fast. It appears to be entering a method twice before it exits like it's being called from another thread.
Here is some code.
private Object m_thisLock = new Object();
private void DisposeLayoutObjects()
{
lock (m_thisLock)
{
Console.WriteLine(String.Format("DisposeLayoutObjects Start (ThreadId:{0})", Thread.CurrentThread.ManagedThreadId));
for (int i = 0; i < MainForm.Layout.ObjectArray.Count; i++)
MainForm.Layout.ObjectArray[i].Dispose();
MainForm.Layout.ObjectArray.Clear();
Console.WriteLine(String.Format("DisposeLayoutObjects End (ThreadId: {0})", Thread.CurrentThread.ManagedThreadId));
}
}
private void LoadLayout()
{
DisposeLayoutObjects()
...
}
protected override void OnKeyUp(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Down:
LoadLayout();
break;
}
}
I am getting the following output when I tap on the Down key fast.
DisposeLayoutObjects Start (ThreadId:9) The thread 0xfb8 has exited with code 0 (0x0). DisposeLayoutObjects Start (ThreadId:9) DisposeLayoutObjects End (ThreadId: 9) DisposeLayoutObjects End (ThreadId: 9)
The thread id is the same, I even added a lock to prevent re-entry. So how is it possible that it's entering DisposeLayoutObjects twice like that?
As a side note my main loop is using Application_Idle event with a PeekMessage for pumping messages. When I tried using a timer I had some UI refresh issues.






