WOhoo!! Sorry sa dugay reply mga bro! Party time man gud diri mao lipong2x pirmi.
Background lang ni sa ako little project. Some istoryans may know who I am so please hush hush

. I also think some of you might be interested in this little project and could use the ideas as well.
The idea is to create a scriptable windows form based application.
Scripting language chosen is javascript. The application exposes an API for script usage.
The script can control all and any aspect of the form. Scripts needs to download any other resources from the INET, read local files, prevent closing of the form, display form messageboxes (not js alert()), report progress ... etc so these are done through the API.
There can be one or more scripts that can interact with the form or interact with its fellow scripts.
A webbrowser control is needed because the scripts can/needs to create html elements (forms and all web element stuff).
So back to the problem.
Right now, I scrapped the threading and sticked to a single thread momentarily. I have traced down to the very first call of Document.InvokeScript. Further down, a script calls one of my API functions "GetContents(url)" to download a resource from the NET which is using WebClient.DownloadStringAsync(url).
Code:
public string GetContents(string url)
{
//snip .......
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadStringAsync(new Uri(url), this); <-- Main form freeze momentarily here but only of very first call!!!!
Application.UseWaitCursor = true;
while (IsDownloadCompleted == false)
{
Application.DoEvents();
}
Application.UseWaitCursor = false;
client.Dispose();
return this.Contents.Context(ctx);
}
Now examining the thread executing WebClient.DownloadStringAsync(url), obviously, it is the main UI thread that's why I used the asynchronous method. But why does it freeze there? (marked in red). It is supposed to continue to the next instruction right? Or am I missing something that the framework needs to initialize some stuff?
@Artoy, thanks for the idea, but using a delegate will cause the delegated function to be called on main thread which I think is the same as directly calling the Document.InvokeScript from the main form in this particular situation.
@Mark, thanks I tried your test app. It appears the background worker works but I'm not totally sure because it completes very fast.Maybe you can try the real scenario I mentioned above? If you're up to it
P.S. I'm just learning .NET so pardon my ignorance in some matters.