Skip to content

Commit

Permalink
异常处理
Browse files Browse the repository at this point in the history
  • Loading branch information
melancn committed Oct 12, 2021
1 parent 03badb7 commit 32e29d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Watching/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Grid>
<Grid.ColumnDefinitions>

<ColumnDefinition MinWidth="100" Width="100"/>
<ColumnDefinition MinWidth="120" Width="120"/>

<ColumnDefinition MinWidth="100"/>
<ColumnDefinition Width="Auto"/>
Expand Down Expand Up @@ -39,8 +39,8 @@
<Label Content="提示标题" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Label Content="提示内容" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1"/>
<Label Content="提示次数" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="2"/>
<Label Content="提示间隔 (ms)" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="3"/>
<Label Content="轮询间隔(ms)" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="4"/>
<Label Content="最小提示间隔 (ms)" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="3"/>
<Label Content="轮询间隔 (ms)" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="4"/>
<Label Content="轮询地址" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="5"/>
<Label Content="页面正则" HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="6" Margin="0,12,0,0"/>
<CheckBox x:Name="is_include" Content="是否包含" HorizontalAlignment="Center" Margin="0,45,0,0" VerticalAlignment="Top" Padding="0" Grid.Row="6"/>
Expand Down
15 changes: 7 additions & 8 deletions Watching/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public void addTextToInfo(string a)
{
Dispatcher.InvokeAsync(() =>
{
logInfo.Text = logInfo.Text + a + "\r\n";
string date = DateTime.Now.ToString("u");
logInfo.Text = logInfo.Text + date + "\r\n" + a + "\r\n";
logInfo.ScrollToVerticalOffset(logInfo.ExtentHeight);
}
);
Expand All @@ -155,7 +156,6 @@ await System.Threading.Tasks.Task.Run(() =>
Console.WriteLine("s Thread ID:#{0}", Thread.CurrentThread.ManagedThreadId);
run_id = System.Threading.Thread.CurrentThread.ManagedThreadId;
string html;
string date;
DateTime now = DateTime.Now;
while (true)
{
Expand All @@ -172,8 +172,9 @@ await System.Threading.Tasks.Task.Run(() =>
{
html = u.GetStringAsync(url).Result;
}
catch (HttpRequestException e)
catch (Exception e)
{
addTextToInfo("错误:" + e.InnerException.Message);
System.Windows.MessageBox.Show(e.Message);
run_id = 0;
is_stop = false;
Expand All @@ -197,8 +198,7 @@ await System.Threading.Tasks.Task.Run(() =>
}
count++;
addTextToInfo("提示次数:" + count.ToString());
date = DateTime.Now.ToString("u");
addTextToInfo(date + " " + title + " " + content);
addTextToInfo(title + " " + content);
if (notifyIcon != null) notifyIcon.ShowBalloonTip(time_out, title, content, ToolTipIcon.Info);
}
else
Expand All @@ -222,8 +222,7 @@ await System.Threading.Tasks.Task.Run(() =>
}
count++;
addTextToInfo("提示次数:" + count.ToString());
date = DateTime.Now.ToString("u");
addTextToInfo(date + " " + title + " " + content);
addTextToInfo(title + " " + content);
if (notifyIcon!=null) notifyIcon.ShowBalloonTip(time_out, title, content, ToolTipIcon.Info);
}
else
Expand All @@ -245,7 +244,7 @@ private void getConfig()
title.Text = ConfigurationManager.AppSettings["title"] ?? "DIY卡免还款签账额20元";
content.Text = ConfigurationManager.AppSettings["content"] ?? "有货";
alert_times.Text = ConfigurationManager.AppSettings["alert_times"] ?? "10";
alert_time.Text = ConfigurationManager.AppSettings["alert_time"] ?? "0";
alert_time.Text = ConfigurationManager.AppSettings["alert_time"] ?? "1000";
interval_time.Text = ConfigurationManager.AppSettings["interval_time"] ?? "35000";
url.Text = ConfigurationManager.AppSettings["url"] ?? "https://shop.cgbchina.com.cn/mall/goods/03140714143403208122?itemCode=03140714143403208122";
url_pattern.Text = ConfigurationManager.AppSettings["url_pattern"] ?? "stock-zero";
Expand Down
4 changes: 2 additions & 2 deletions Watching/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("2.2.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]

0 comments on commit 32e29d7

Please sign in to comment.