Hello all,
I have a really annoying issue with a little app I've written and I have absolutely no idea what's causing it. The app is to check the results in an online competition which doesn't list the results; instead it has the number of votes each contestant has on their entrant page but my app grabs all the links from the list of contestants, then grabs the data from their page and writes it to a textbox. Here's the code:
Now, the issue I'm facing is that when this app is running (it's currently in the VS debugger and I haven't tested it running without a debugger attached yet) it puts my screen to sleep instantly when the window is in focus. The minute it is minimised, the problem goes away. If I keep my mouse moving, I can see the form but the minute I stop my mouse, off goes the screen.
Any ideas what's causing this?
Thanks,
Tom
P.S. I know it's not the neatest or most efficient code in the world - I haven't been learning C# for long :)
I have a really annoying issue with a little app I've written and I have absolutely no idea what's causing it. The app is to check the results in an online competition which doesn't list the results; instead it has the number of votes each contestant has on their entrant page but my app grabs all the links from the list of contestants, then grabs the data from their page and writes it to a textbox. Here's the code:
Code:
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCheck_Click(object sender, EventArgs e)
{
string webaddress = "";
string name = "";
string votes = "";
string line = "";
using (WebClient client = new WebClient())
{
client.DownloadFile(@"http://www.mobilityawarenessmonth.com/local-heroes/?icp=1&ihpp=3900", @"C:\\NMEDA\\list.html");
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(@"C:\\NMEDA\\list.html");
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
HtmlAttribute att = link.Attributes["href"];
if (att.Value.ToString().Contains("entrant"))
{
webaddress = att.Value.ToString();
using (WebClient client2 = new WebClient())
{
client2.DownloadFile(@webaddress, @"C:\\NMEDA\\file.html");
}
using (StreamReader reader = new StreamReader(@"C:\\NMEDA\\file.html"))
{
while ((line = reader.ReadLine()) != null)
{
if (line.Contains("votecountvotes"))
{
votes = line.ToString();
}
if (line.Contains(@"in the 2014 National Mobility Awareness Month Local Hero contest! "))
{
name = line.ToString();
}
}
}
// Tidy Votes
votes = votes.Trim();
string[] v = votes.Split('<');
votes = v[0].ToString();
votes = votes.Replace(",", "");
// Tidy entrant name
name = name.Trim();
string[] ent = name.Split('-');
name = ent[0].ToString();
name = name.Replace("Vote for ", "");
txtResults.AppendText(votes + " | " + name + " | " + webaddress + "\r\n");
}
}
doc.Save("C:\\NMEDA\\list.html");
}
}
}
Now, the issue I'm facing is that when this app is running (it's currently in the VS debugger and I haven't tested it running without a debugger attached yet) it puts my screen to sleep instantly when the window is in focus. The minute it is minimised, the problem goes away. If I keep my mouse moving, I can see the form but the minute I stop my mouse, off goes the screen.
Any ideas what's causing this?
Thanks,
Tom
P.S. I know it's not the neatest or most efficient code in the world - I haven't been learning C# for long :)