weird crash upon using the invoker
im using the invoker to do something after a short delay
when i do the task required using a button it all works when
i use the invoker to do it, it crash the app
heres the invoker code
_delayMSE2.Set();
// open the ResetEvent gate, to discard these delays
Thread.Sleep(20);
// let all pending through the gate
_delayMSE2.Reset();
// close the gate
TBDelay2.BeginInvoke(res2 =>
{
// callback code
// check how we exited, via timeout or signal.
bool timedOut2 = TBDelay2.EndInvoke(res2);
if (timedOut2)
Dispatcher.CurrentDispatcher.Invoke(
new ActionToRunWhenUserStopstyping2(DoWhatEverYouNeed2),
DispatcherPriority.Input);
}, null);
----
heres the task
private void conexiononinputdelay()
{
if (tabControl1.SelectedTab == tabPage1)
{
Random r = new Random();
int n = r.Next();
var page4 = new TabPage(roombox.Text);
tabControl1.TabPages.Add(page4);
tabControl1.SelectedTab = page4;
var browser = new WebBrowser();
browser.Visible = true;
browser.Left = -browser.Width;
browser.ScriptErrorsSuppressed = true;
browser.Dock = DockStyle.Fill;
// contextMenuStrip10.Visible is the menu that should show when right clicked
browser.IsWebBrowserContextMenuEnabled = false;
page4.Controls.Add(browser);
browser.Name = roombox.Text + n;
page4.Name = roombox.Text + n;
browser.Navigate("http://www.tinychat.com/" + roombox.Text);
// MessageBox.Show("broswer is " + browser.Name + "page name is " + page4.Name);
}
else
{
foreach (TabPage page in tabControl1.TabPages)
{
foreach (Control c in page.Controls)
{
string tabpagex = tabControl1.SelectedTab.Name;
if (c is WebBrowser && c.Name == tabpagex)
{
((WebBrowser)c).Url = new Uri(@"http://www.tinychat.com/" + roombox.Text);
tabControl1.SelectedTab.Name = roombox.Text;
tabControl1.SelectedTab.Text = roombox.Text;
c.Name = roombox.Text;
}
else
{
}
}
}
}
}
note that when the task is executed using a button by example (click on a button event)
everything works just fine without any problem i tried removing anything else
that could interfer with this and i get the exact same crash