The program now prevents closing if it's still downloading an image

This commit is contained in:
Norbi Peti 2016-04-19 21:57:20 +02:00
parent a811d376dc
commit 1c4e88b6a5
3 changed files with 21 additions and 1 deletions

View file

@ -19,6 +19,16 @@ namespace DEIFR
checkBox1.Checked = Program.KeepImages;
Program.Progress = progressBar1;
Program.AllProgress = progressBar2;
this.FormClosing += Form1_FormClosing;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!ImageDownloader.Stop)
{
ImageDownloader.Stop = true;
e.Cancel = true;
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)

View file

@ -96,6 +96,14 @@ namespace DEIFR
private static bool Next()
{
if (Stop)
{
Program.Form.Invoke(new Action(delegate
{
Program.Form.Close();
}));
return true;
}
if (enumerator.MoveNext())
{
JToken result = enumerator.Current;
@ -113,7 +121,6 @@ namespace DEIFR
else
return false; //Otherwise we don't know what is there
}
//Image.FromStream(respstr).Save(i + "." + s.Split('/').Last().Split('.')[1]);
string path = id + "." + s.Split('/').Last().Split('.')[1].Split('?')[0]; //?: FB and similar sites
using (WebClient client = new WebClient())
{
@ -140,5 +147,7 @@ namespace DEIFR
}
return true;
}
public static bool Stop { get; set; }
}
}

View file

@ -29,6 +29,7 @@ namespace DEIFR
return;
}
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
if (File.Exists("DEIFRSettings.ini"))
{
string[] ss = File.ReadAllLines("DEIFRSettings.ini");