Browse Source

basic implementation of exception dispatch on avalonia.native.

pull/3451/head
Dan Walmsley 7 years ago
parent
commit
c35755857c
  1. 5
      src/Avalonia.Native/Avalonia.Native.csproj
  2. 10
      src/Avalonia.Native/CallbackBase.cs
  3. 10
      src/Avalonia.Native/PlatformThreadingInterface.cs

5
src/Avalonia.Native/Avalonia.Native.csproj

@ -19,8 +19,9 @@
<ItemGroup> <ItemGroup>
<SharpGenMapping Include="Mappings.xml" /> <SharpGenMapping Include="Mappings.xml" />
<PackageReference Include="SharpGenTools.Sdk" Version="1.1.2" PrivateAssets="all" /> <PackageReference Include="SharpGenTools.Sdk" Version="1.2.1" PrivateAssets="all" />
<PackageReference Include="SharpGen.Runtime.COM" Version="1.1.0" /> <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="..\..\packages\Avalonia\Avalonia.csproj" />
<ProjectReference Include="..\Avalonia.Dialogs\Avalonia.Dialogs.csproj" /> <ProjectReference Include="..\Avalonia.Dialogs\Avalonia.Dialogs.csproj" />
</ItemGroup> </ItemGroup>

10
src/Avalonia.Native/CallbackBase.cs

@ -2,11 +2,12 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Runtime.ExceptionServices;
using SharpGen.Runtime; using SharpGen.Runtime;
namespace Avalonia.Native namespace Avalonia.Native
{ {
public class CallbackBase : SharpGen.Runtime.IUnknown public class CallbackBase : SharpGen.Runtime.IUnknown, IExceptionCallback
{ {
private uint _refCount; private uint _refCount;
private bool _disposed; private bool _disposed;
@ -76,5 +77,12 @@ namespace Avalonia.Native
{ {
} }
public void RaiseException(Exception e)
{
var exceptionInfo = ExceptionDispatchInfo.Capture(e);
PlatformThreadingInterface.s_exceptionDispatchInfo = exceptionInfo;
}
} }
} }

10
src/Avalonia.Native/PlatformThreadingInterface.cs

@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System; using System;
using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using Avalonia.Native.Interop; using Avalonia.Native.Interop;
using Avalonia.Platform; using Avalonia.Platform;
@ -12,6 +13,8 @@ namespace Avalonia.Native
{ {
public class PlatformThreadingInterface : IPlatformThreadingInterface public class PlatformThreadingInterface : IPlatformThreadingInterface
{ {
public static ExceptionDispatchInfo s_exceptionDispatchInfo;
class TimerCallback : CallbackBase, IAvnActionCallback class TimerCallback : CallbackBase, IAvnActionCallback
{ {
readonly Action _tick; readonly Action _tick;
@ -82,6 +85,13 @@ namespace Avalonia.Native
cancellation = null; cancellation = null;
} }
} }
if(s_exceptionDispatchInfo != null)
{
// TODO terminate NSApp.
s_exceptionDispatchInfo.Throw();
}
} }
} }

Loading…
Cancel
Save