System.Threading and Object.refresh()

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    7 posts
    Member since:
    Oct 2010

    Posted 04 Jul 2012 Link to this post

    Hello All having issues with the HTMLControl.Refresh()

    In the below code, I am creating a new thread to monitor a specific Object for changes.  The code "freezes" at the HTMLControl.Refresh() part.  No error are generated, it just get stuck and cant get pass that call.  Any ideas?

    //Service that actively monitors a spesific HTML DOM Object for changes
    //IF the HTMLControl is found the object monitored, a true is set
    namespace Newton2_Automation.SharedFunctionLib
    {
        public class MonitorHtmlObject
        {
     
            public MonitorHtmlObject(HtmlControl monitorControl, string htmlId = null, string htmlClass = null)
            {
                _monitorControl = monitorControl;
                _htmlId = htmlId;
                _htmlClass = htmlClass;
            }      
             
            public void Start()
            {
                oThread = new Thread(new ThreadStart(HTMLRunner));
                oThread.Start();
                while (!oThread.IsAlive) ;
            }
         
            public bool Output;
     
            public void Stop()
            {
                oThread.Abort();
            }      
            private void HTMLRunner()
            {
                Output = false;
                while (true)
                {
                    try
                    {
                        if ((monitorControl.Find.ByAttributes(_htmlId)) != null)
                        {
                            Output = true;
                        }                   
                    }
                    catch
                    {
                        continue;
                    }
                    _monitorControl.Refresh();
                }
     
            }
            private Thread oThread;
     
            private HtmlControl _monitorControl;
            private HtmlControl monitorControl
            {
                get
                {
                    while (_monitorControl.IsRefresh == true)
                    {
                        Thread.Sleep(100);
                         
                    }
                    return _monitorControl;
                }
     
            }
     
            private string _htmlId;
     
            private string _htmlClass;
     
        }
    }

    This how its being called:
    foreach (HtmlDiv col in getPlaceHolders)
                {
                    int ColCounbt = new int();
                    try
                    {
                        ColCounbt = col.Find.ByTagIndex("ul", 0).ChildNodes.Count;
                    }
                    catch
                    {
                        ColCounbt = 0;
                        continue;
                    }
                    if (ColCounbt > 0)
                    {
                        HtmlListItem[] GagetColection = new HtmlListItem[col.Find.ByTagIndex("ul", 0).ChildNodes.Count];
                        for (int i = 0; i < GagetColection.Count(); i++)
                        {
                            GagetColection[i] = ((HtmlUnorderedList)(col.Find.ByTagIndex<HtmlUnorderedList>("ul", 0))).ChildNodes[i].As<HtmlListItem>();
                        }
     
                        foreach (HtmlListItem item in GagetColection)
                        {
                            HtmlUnorderedList toCol = getPlaceHolders[sf.GenRandomNum(0, getPlaceHolders.Count())].Find.ById<HtmlUnorderedList>("undefinedGadgetHolder");
                            item.Refresh();
                            HtmlDiv GadgetHeader = item.Find.ByAttributes<HtmlDiv>("class=~gadget-head");
                            MonitorHtmlObject monitor = new MonitorHtmlObject(toCol, "class=gadget-placeholder");
                            monitor.Start();
                            GadgetHeader.DragTo(toCol, OffsetReference.AbsoluteCenter, Point.Empty);
                                Log.WriteLine(monitor.Output.ToString());
                            monitor.Stop();
                            ActiveBrowser.WaitForAjax(10000);
                            System.Threading.Thread.Sleep(5000);
                        }
                         
                    }          
                }



  2. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 06 Jul 2012 Link to this post

    Hi,

    I would eliminate the threading and split up the mouse drag into separate steps so I can do my verification in the middle of it like this:

    //GadgetHeader.DragTo(toCol, OffsetReference.AbsoluteCenter, Point.Empty);
    GadgetHeader.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick);
    Manager.Desktop.Mouse.Move(GadgetHeader.GetRectangle(), toCol.GetRectangle());
      
    // We are in the middle of the drag.
    // Perform DOM verifications here
      
    Manager.Desktop.Mouse.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftUp, toCol.GetRectangle());

    Regards,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top