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?
This how its being called:
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);
}
}
}