473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DisconnectedContext was detected - WebBrowser.Document.Write

Make a WebBrowser control, and make a bunch of timers / threads that
continually call WebBrowser.Document.Write. Eventually, this happens:

DisconnectedContext was detected
Message: Context 0x1a1530' is disconnected. Releasing the interfaces
from the current context (context 0x1a13c0).This may cause corruption
or data loss. To avoid this problem, please ensure that all contexts/
apartments stay alive until the applicationis completely done with the
RuntimeCallableWrappers that represent COM components that liveinside
them.

I believe that eventually the WebBrowser takes so long to refresh that
it doesn't complete its job before the next Write, and this occurs.
This explains why it occurs quicker if the Writing speed is increased,
and why it always enivitably happens, even if the writing speed is
slowed. Since, as the page grows in size, the refresh time increases.

Any fixes? It just happens. I can't catch it as an exception.

Zytan

Apr 6 '07 #1
6 7503
Furthermore, if I tell the debugger to continue after the
"DisconnectedContext was detected " error, this occurs:

ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context
0x1a0ba0 to COM context 0x1a0d10 for 60 seconds. The thread that owns
the destination context/apartment is most likely either doing a non
pumping wait or processing a very long running operation without
pumping Windows messages. This situation generally has a negative
performance impact and may even lead to the application becoming non
responsive or memory usage accumulating continually over time. To
avoid this problem, all single threaded apartment (STA) threads should
use pumping wait primitives (such as CoWaitForMultipleHandles) and
routinely pump messages during long running operations.

Zytan

Apr 6 '07 #2
What kind of timers are you using, and how are you making the calls? It
looks like you are trying to do a cross apartment call, when in fact, if
your timers are firing on a non-UI thread, you should be making your calls
to Document.Write through a delegate passed to the Invoke method on the
WebBrowser control.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Furthermore, if I tell the debugger to continue after the
"DisconnectedContext was detected " error, this occurs:

ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context
0x1a0ba0 to COM context 0x1a0d10 for 60 seconds. The thread that owns
the destination context/apartment is most likely either doing a non
pumping wait or processing a very long running operation without
pumping Windows messages. This situation generally has a negative
performance impact and may even lead to the application becoming non
responsive or memory usage accumulating continually over time. To
avoid this problem, all single threaded apartment (STA) threads should
use pumping wait primitives (such as CoWaitForMultipleHandles) and
routinely pump messages during long running operations.

Zytan

Apr 6 '07 #3
What kind of timers are you using,

The standard Timer control. I don't need any timers to cause this.
In fact, my latest test program has no timers.
and how are you making the calls?
I am calling WebBrowser.InvokeRequired to see if the thread is in the
right thread. If true: it calls WebBrowser.BeginInvoke (asynchronous)
to call the same function from the GUI thread. If false: it runs
WebBrowser.Write.
It
looks like you are trying to do a cross apartment call, when in fact, if
your timers are firing on a non-UI thread, you should be making your calls
to Document.Write through a delegate passed to the Invoke method on the
WebBrowser control.
Forget about the Timer controls, since they just confuse the issue at
hand, I am sorry I brought them up. And I believe I am already doing
the rest, as you suggest, properly. I can post a small source
example, if you wish.

Thanks, Nicholas

Zytan

Apr 10 '07 #4
and how are you making the calls?
>
I am calling WebBrowser.InvokeRequired to see if the thread is in the
right thread. If true: it calls WebBrowser.BeginInvoke (asynchronous)
to call the same function from the GUI thread. If false: it runs
WebBrowser.Write.
Note that if I make the program repeatedly call all the above from the
GUI thread (say, in response to a button click), where no other
threads exist, then it can write and write and write, and nothing bad
happens.

The error occurs only when non-GUI threads are doing the writing. In
fact, ONLY ONE non-GUI thread needs to be writing to it to cause the
error (without the GUI thread doing anything itself).

Zytan

Apr 10 '07 #5
Source code: Three buttons: START, STOP (starts and stops worker
threads), and GUITHREAD (does work in the main gui thread). The code
isn't 'perfect' in that if you keep clicking START over and over, and
it makes more and more threads, using the same variable reference over
and over.

namespace MultithreadGUI
{
public partial class MainForm : Form
{
private Thread myThread;
private volatile bool m_bThreadRunning = false;

public MainForm()
{
InitializeComponent();
}

private void MainForm_FormClosed(object sender,
FormClosedEventArgs e)
{
m_bThreadRunning = false;
}

delegate void MyWriteLine_Delegate(string s);
private void MyWriteLine(string s)
{
if (webLog.InvokeRequired)
{
MyWriteLine_Delegate funcPtr = MyWriteLine;
object[] argArray = { s };
webLog.BeginInvoke(funcPtr, argArray);

}
else
{
if (webLog.Document == null)
webLog.Navigate("about:blank");
webLog.Document.Write(s + "<br>" +
Environment.NewLine);
webLog.Document.Window.ScrollTo(0, int.MaxValue);
}
}

private int m_countThread1 = 0;
private void myThreadFunc1()
{
while (m_bThreadRunning)
{
// Thread.Sleep(400);
m_countThread1++;
MyWriteLine("m_countThread1 = " + m_countThread1);
}
}

private void btnStart_Click(object sender, EventArgs e)
{
m_bThreadRunning = true;
myThread = new Thread(myThreadFunc1);
myThread.Start();
}

private void btnStop_Click(object sender, EventArgs e)
{
m_bThreadRunning = false;
}

private void btnGuiThread_Click(object sender, EventArgs e)
{
for (int i = 0; i < 1000000000; i++)
MyWriteLine(i + ": " + Guid.NewGuid().ToString());
}
}
}

Try these things:

1. click GUITHREAD, all is ok.
2. click START it breaks down (just one worker thread)
3. add Thread.Sleep() to slow it down, and keep pressing START over
and over (or hold ENTER down if it's in focus to keep pressing it),
and wait, it breaks down.

Zytan

Apr 10 '07 #6
It appears WebBrowser is simply broken.

Any thoughts / ideas?

Zytan

Apr 16 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Trevor Fairchild | last post by:
I'm trying to have VB6 write an html file during run-time, with some VBScript functionality. The intent is to display images based on the current record within the program - using a WebBrowser -...
1
by: BKM | last post by:
I've been using the following 2 ways to make sure my WebBrowser is finished loading a page before continuing with the next code. do:doevents:loop while WebBrowser.Busy do:doevents:loop until...
0
by: Dean Hinson | last post by:
Hello, I have received this message when I exit a program I am working on... DisconnectedContext was detected Message: Context 0x18fbd0' is disconnected. Releasing the interfaces from the...
4
by: Steve Richter | last post by:
I would like to build an HTML stream as a string and have the WebBrowser control render that HTML. Then on PostBack, or whatever it is called, I would like my code to be the one that receives what...
0
by: Andy Bates | last post by:
Hi - This issue seems to have been kicking around since the dawn of time and no one appears to have come up with an answer. In short the MHT/MSHTML provides a method of archiving an HTML page...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: David Veeneman | last post by:
In .NET 2.0, how do I clear the contents of a web browser control? I'm using a WebBrowser control in a Windows Form app to display strings genrated by my application and formatted as HTML--I'm...
2
by: mr_doles | last post by:
I am trying to match users from one database with users in AD to get an e-mail address. The program works but right before it exits I get the following message. DisconnectedContext was detected...
0
by: Kim Briggs | last post by:
I am developing an BHO/Explorer Bar using Addin Express for Internet Explorer (a framework to get MSHTML/COM Interop newbies like myself off the ground). Target browser is IE7. Occasionally, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.