Guess I was not very clear so here is what's going on.

Originally Posted by
MarkCueing
Can you give some steps by steps process? when this method triggered? and how you triggered this? Is it right after the user click the button?
Let's consider my prototype to make things a bit simpler.
1. The main form has a button control. On form load an html file in the local FS is loaded to the webbrowser control. Here is the contents of the html file :
Code:
<html>
<body>
<div id='contents'></div>
</body>
</html>
2. On the DocumentCompleted event of the WebBrowser control. A JS file (still on the local FS) is injected to the current Document of the WebBrowser control. Here is the contents of the JS file
Code:
function displayCNN() {
//GetContents is an API call
var contents = GetContents('http://cnn.com');
$('contents').innerHTML = contents;
}
4. In the OnClick handler of the button control on the form.
Code:
public void button_OnClick(object sender, EventArgs e)
{
//this calls the displayCNN JS function
this.browser.Document.InvokeScript('displayCNN', null);
}
So basically that is how the "GetContents" is triggered.

Originally Posted by
MarkCueing
I need also to see your method client_DownloadStringCompleted, and client_DownloadProgressChanged Inorder for me to simulate closer to your approach.
Just set some IVAR that will contain the contents to be returned by the "GetContents(...)" method to the script. e.g. this.contents = e.Result.
In the code I posted earlier I returned this.Contents.Context[ctx], just change this to the IVAR you used in client_DownloadStringCompleted. (this.contents). For client_DownloadProgressChanged just leave that blank or omit setting that event, it doesn't matter.

Originally Posted by
MarkCueing
also when you called that client.DownloadStringAsync(new Uri(url), this), although I can figure it out that "this" refers to the object token, as it only have 2 overloads out there. I still don't know how the class is being constructed. The class itself is the object you want to pass for this call? above on this post you said that want to download the resource by calling WebClient.DownloadStringAsync(url). So which is which?
Just base on the code I posted earlier

Originally Posted by
MarkCueing
another thing I want to ask, what kind of resource you want to download? FILE? BYTES?
The resource can be any plain text resource the script needs. I have another API for downloading binary resources and that's another story.

Originally Posted by
MarkCueing
I don't know if you agree with this, though I still not yet sure, the keyword "using" seems useful on this scene.
You are calling client.dispatch() explicitly, I feel not safe on this manner especially if you work with threads, this may lead to dispose your object while the thread is running.
I don't like using language specific constructs. I prefer to keep a coding standard across all progamming languages I use, but that's just me.

Originally Posted by
ArToy
i tried the delegate. it does not hang the form even if naa pa sleep ang sulod sa delegate. pero if naa sleep sa javascript mo hang na xa. hehehe.
Try it with the code I posted earlier. I enumerated the steps above 
My question is why does my main form momentarily freeze on the client.DownloadStringAsync() as this is supposed to be asynchchronous? And why does it ONLY occur on the very first call?
Oh and I also have a theory that whatever thread that executes browser.Document.InvokeScript(...) is the thread executing the JS function?