Skip to content

Commit

Permalink
basic implementation of exception dispatch on avalonia.native.
Browse files Browse the repository at this point in the history
  • Loading branch information
danwalmsley committed Jan 19, 2020
1 parent 93b94a5 commit c357558
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Avalonia.Native/Avalonia.Native.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

<ItemGroup>
<SharpGenMapping Include="Mappings.xml" />
<PackageReference Include="SharpGenTools.Sdk" Version="1.1.2" PrivateAssets="all" />
<PackageReference Include="SharpGen.Runtime.COM" Version="1.1.0" />
<PackageReference Include="SharpGenTools.Sdk" Version="1.2.1" PrivateAssets="all" />
<PackageReference Include="SharpGen.Runtime" Version="1.2.1" />
<PackageReference Include="SharpGen.Runtime.COM" Version="1.2.0" />
<ProjectReference Include="..\..\packages\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\Avalonia.Dialogs\Avalonia.Dialogs.csproj" />
</ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion src/Avalonia.Native/CallbackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using System.Runtime.ExceptionServices;
using SharpGen.Runtime;

namespace Avalonia.Native
{
public class CallbackBase : SharpGen.Runtime.IUnknown
public class CallbackBase : SharpGen.Runtime.IUnknown, IExceptionCallback
{
private uint _refCount;
private bool _disposed;
Expand Down Expand Up @@ -76,5 +77,12 @@ protected virtual void Destroyed()
{

}

public void RaiseException(Exception e)
{
var exceptionInfo = ExceptionDispatchInfo.Capture(e);

PlatformThreadingInterface.s_exceptionDispatchInfo = exceptionInfo;
}
}
}
10 changes: 10 additions & 0 deletions src/Avalonia.Native/PlatformThreadingInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using System.Runtime.ExceptionServices;
using System.Threading;
using Avalonia.Native.Interop;
using Avalonia.Platform;
Expand All @@ -12,6 +13,8 @@ namespace Avalonia.Native
{
public class PlatformThreadingInterface : IPlatformThreadingInterface
{
public static ExceptionDispatchInfo s_exceptionDispatchInfo;

class TimerCallback : CallbackBase, IAvnActionCallback
{
readonly Action _tick;
Expand Down Expand Up @@ -82,6 +85,13 @@ public void RunLoop(CancellationToken cancellationToken)
cancellation = null;
}
}

if(s_exceptionDispatchInfo != null)
{
// TODO terminate NSApp.

s_exceptionDispatchInfo.Throw();
}
}
}

Expand Down

0 comments on commit c357558

Please sign in to comment.