Click here to Skip to main content
15,887,351 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello Friends
First of all here are my codes:
C#
this.WebBrowser.Navigate(string.Format("http://facenama.com/{0}", "MeysamTM"));

while (this.WebBrowser.ReadyState != WebBrowserReadyState.Complete)
   Application.DoEvents();

foreach (string contact in this.Contacts.Items)
{
    this.WebBrowser.Document.InvokeScript("postform_open");

    object[] args = new object[1] { contact };

    this.WebBrowser.Document.InvokeScript("postform_sharewith_user", args);

    this.WebBrowser.Document.Window.Frames[0].Document.GetElementsByTagName("body")[0].InnerHtml = this.Message.Text;

    this.WebBrowser.Document.InvokeScript("postform_submit");
}

These part of my code sends a message to several users in a website using WebBrowser (It suppose to, at least). But always the message will be send to last contact in the list.
I think if I make JavaScripts wait at the end of the foreach loop the problem will be fix.
What do you think? Is that even possible?
Posted

1 solution

I find out finally!

Some Tasks can not repeat in a single method when I am working with WebBrowser. I did not understand why?! I just used a Timer to avoid this issue. I mean every step of the loop will run in Timer.Tick() handler method; You should attention that some changes must be done such as defining Fields instead of local variables and controlling exceptions.

I hope My Question and its answer will be helpful for others.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900