Open config file from executable directory regardless of working directory (fixes startup issue)

Fixed ExceptionEvent not invoking to main thread
Bit more exception handling while shutting down
This commit is contained in:
Mark van Renswoude 2019-08-25 20:02:22 +02:00
parent c334b7fdac
commit 5e0513fc81
4 changed files with 26 additions and 3 deletions

View File

@ -48,8 +48,20 @@ namespace IPCamAppBar
public void Dispose() public void Dispose()
{ {
cancelTaskTokenSource.Cancel(); cancelTaskTokenSource.Cancel();
try
{
streamTask?.Wait(); streamTask?.Wait();
} }
catch (AggregateException e)
{
if (e.InnerExceptions.Count == 1 && e.InnerExceptions[0] is TaskCanceledException)
return;
throw;
}
catch (TaskCanceledException) { }
}
private async Task Fetch(string url, CancellationToken cancellationToken) private async Task Fetch(string url, CancellationToken cancellationToken)

View File

@ -22,7 +22,7 @@ namespace IPCamAppBar
Disposed += (sender, args) => Disposed += (sender, args) =>
{ {
cameraStream?.Dispose(); cameraStream.Dispose();
}; };
} }
@ -80,6 +80,12 @@ namespace IPCamAppBar
private void CameraStreamOnStreamException(object sender, StreamExceptionEventArgs args) private void CameraStreamOnStreamException(object sender, StreamExceptionEventArgs args)
{ {
if (InvokeRequired)
{
Invoke(new Action(() => { CameraStreamOnStreamException(sender, args); }));
return;
}
IssueLabel.Text = args.Exception.Message; IssueLabel.Text = args.Exception.Message;
IssueLabel.Visible = true; IssueLabel.Visible = true;
IssueLabel.BringToFront(); IssueLabel.BringToFront();

View File

@ -31,6 +31,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Diagnostics.Contracts;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -16,7 +18,9 @@ namespace IPCamAppBar
{ {
InitializeComponent(); InitializeComponent();
using (var file = File.OpenText(@"config.json")) // ReSharper disable once PossibleNullReferenceException
// ReSharper disable once AssignNullToNotNullAttribute
using (var file = File.OpenText(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "config.json")))
{ {
var serializer = new JsonSerializer(); var serializer = new JsonSerializer();
config = (Config)serializer.Deserialize(file, typeof(Config)); config = (Config)serializer.Deserialize(file, typeof(Config));