U
uzi
Hi
Recently I had a problem in which I had window opened that had a slider
which was updated by raising an event on that window.
The background window was still available, and the user clicked on it
causing it to perform a long time operation.
During this operation the events for the update position started
accumulating since the main GUI thread was busy, and I got an exception that
the thread pool has no enough threads to perform the operation.
This is when decided to open the window on another GUI thread.
Below is the code snippet I used for creating the new GUI thread.
My problem is that sometime i get an exception of
System.InvalidOperationException: The object is currently in use elsewhere
Does anyone have an idea why???
Thanks
Uzi
private class NewGuiThreadWrapper
{
private ApplicationContext m_Cntx;
ManualResetEvent m_Ev;
public ApplicationContext ApplicationCntx
{
get { return m_Cntx; }
}
public NewGuiThreadWrapper(ManualResetEvent ev)
{
m_Ev = ev;
new Thread(new ThreadStart(StartNewGuiThread)).Start();
}
private void StartNewGuiThread()
{
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
m_Cntx = new ApplicationContext(new MyForm());
m_Ev.Set();
Application.Run(m_Cntx);
}
}
Recently I had a problem in which I had window opened that had a slider
which was updated by raising an event on that window.
The background window was still available, and the user clicked on it
causing it to perform a long time operation.
During this operation the events for the update position started
accumulating since the main GUI thread was busy, and I got an exception that
the thread pool has no enough threads to perform the operation.
This is when decided to open the window on another GUI thread.
Below is the code snippet I used for creating the new GUI thread.
My problem is that sometime i get an exception of
System.InvalidOperationException: The object is currently in use elsewhere
Does anyone have an idea why???
Thanks
Uzi
private class NewGuiThreadWrapper
{
private ApplicationContext m_Cntx;
ManualResetEvent m_Ev;
public ApplicationContext ApplicationCntx
{
get { return m_Cntx; }
}
public NewGuiThreadWrapper(ManualResetEvent ev)
{
m_Ev = ev;
new Thread(new ThreadStart(StartNewGuiThread)).Start();
}
private void StartNewGuiThread()
{
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
m_Cntx = new ApplicationContext(new MyForm());
m_Ev.Set();
Application.Run(m_Cntx);
}
}