473,786 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DisconnectedCon text was detected - WebBrowser.Docu ment.Write

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

DisconnectedCon text 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
RuntimeCallable Wrappers 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 7530
Furthermore, if I tell the debugger to continue after the
"DisconnectedCo ntext was detected " error, this occurs:

ContextSwitchDe adlock 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 CoWaitForMultip leHandles) 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.co m

"Zytan" <zy**********@g mail.comwrote in message
news:11******** **************@ e65g2000hsc.goo glegroups.com.. .
Furthermore, if I tell the debugger to continue after the
"DisconnectedCo ntext was detected " error, this occurs:

ContextSwitchDe adlock 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 CoWaitForMultip leHandles) 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.Invo keRequired to see if the thread is in the
right thread. If true: it calls WebBrowser.Begi nInvoke (asynchronous)
to call the same function from the GUI thread. If false: it runs
WebBrowser.Writ e.
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.Invo keRequired to see if the thread is in the
right thread. If true: it calls WebBrowser.Begi nInvoke (asynchronous)
to call the same function from the GUI thread. If false: it runs
WebBrowser.Writ e.
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_bThreadRunnin g = false;

public MainForm()
{
InitializeCompo nent();
}

private void MainForm_FormCl osed(object sender,
FormClosedEvent Args e)
{
m_bThreadRunnin g = false;
}

delegate void MyWriteLine_Del egate(string s);
private void MyWriteLine(str ing s)
{
if (webLog.InvokeR equired)
{
MyWriteLine_Del egate funcPtr = MyWriteLine;
object[] argArray = { s };
webLog.BeginInv oke(funcPtr, argArray);

}
else
{
if (webLog.Documen t == null)
webLog.Navigate ("about:blank") ;
webLog.Document .Write(s + "<br>" +
Environment.New Line);
webLog.Document .Window.ScrollT o(0, int.MaxValue);
}
}

private int m_countThread1 = 0;
private void myThreadFunc1()
{
while (m_bThreadRunni ng)
{
// Thread.Sleep(40 0);
m_countThread1+ +;
MyWriteLine("m_ countThread1 = " + m_countThread1) ;
}
}

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

private void btnStop_Click(o bject sender, EventArgs e)
{
m_bThreadRunnin g = false;
}

private void btnGuiThread_Cl ick(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
3475
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 - plus some buttons to dynamically resize the image. I have gotten almost everything to work - I put in a function to simply disable the right-click option of the browser, but none of the other functions work. If I copy the source data out of...
1
21314
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 WebBrowser.ReadyState = STATE_COMPLETE (or something like that. I don't have the code in front of me) But, for some reason, occasionally the code continues past the loops even
0
1311
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 current context (context 0x18fa80).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM...
4
12011
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 the WebBrowser control is sending. Effectively, my code would be the web server and the WebBrowser control would be the web client. All the examples I am seeing have the WebBrowser control being directed to a URL from which to get the HTML...
0
3580
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 into a single MIME encoded file that specifies all of the resources for a page in a single file. This makes a lot of sense as if you could pass one of these to the
0
5576
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
1
41023
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 not using it to do any actual web browsing. I use 'webBrowser1.DocumentText = myText' to load an HTML string into the control. But I can't clear that text when I want to load a new string into the control.
2
4851
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 Message: Context 0x1a04b0' is disconnected. Releasing the interfaces from the current context (context 0x1a0340).This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/ apartments stay alive until the...
0
1432
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 get this message (not reliably reproducible but seems to happen with >1 tabs open -- so >1 BHO instances -- and around tab open/close events): DisconnectedContext was detected
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.