root/honeyclient/branches/exp/bhenderson-browser_automation/BrowserAutomation/IE.cs

Revision 1755, 1.8 kB (checked in by bhenderson, 5 months ago)

Reduced Processor hogging from hard timeout thread

  • Property svn:executable set to *
Line 
1 using System;
2 using System.Linq;
3 using System.Text;
4 using System.Threading;
5 using WatiN.Core;
6
7 namespace BrowserAutomation
8 {
9     class IE
10     {
11         private WatiN.Core.IE ie;
12         private Thread hardTimeoutThread;
13         private Thread ieThread;
14         private bool started;
15         private String url;
16         private DateTime startTime;
17         private TimeSpan duration;
18
19         /// <summary>
20         /// Constructor for an instance of Firefox
21         /// </summary>
22         /// <param name="url">URL to be navigated to</param>
23         public IE(string url)
24         {
25             this.url = url;
26             started = false;
27             hardTimeoutThread = new Thread(new ThreadStart(HardTimeoutCallback));
28             ieThread = new Thread(new ThreadStart(IECallback));
29             ieThread.SetApartmentState(ApartmentState.STA);
30             ieThread.Start();
31             hardTimeoutThread.Start();
32         }
33
34         private void IECallback()
35         {
36             ie = new WatiN.Core.IE();
37                
38             ie.GoTo(url);
39             Thread.Sleep(1000);
40             ie.Close();
41                
42             hardTimeoutThread.Abort();
43             ieThread.Abort();
44         }
45
46         /// <summary>
47         ///
48         /// </summary>
49         private void HardTimeoutCallback()
50         {
51             while (true)
52             {
53                 if (!started)
54                 {
55                     started = true;
56                     startTime = DateTime.Now;
57                 }
58
59                 Thread.Sleep(100);
60                 duration = DateTime.Now - startTime;
61
62                 if (duration.Seconds >= 30)
63                 {
64                     ie.Close();
65                     ieThread.Abort();
66                     hardTimeoutThread.Abort();
67                 }
68             }
69         }
70     }
71 }
Note: See TracBrowser for help on using the browser.