I'm trying to translate this C# code to VB.Net
public event EventHandler<OnBackgroundEnteringEventArgs> OnBackgroundEntering;
public async Task SaveStateAsync()
{
var suspensionState = new SuspensionState()
{
SuspensionDate = DateTime.Now
};
var target = OnBackgroundEntering?.Target.GetType();
var onBackgroundEnteringArgs = new OnBackgroundEnteringEventArgs(suspensionState, target);
OnBackgroundEntering?.Invoke(this, onBackgroundEnteringArgs);
await ApplicationData.Current.LocalFolder.SaveAsync(stateFilename, onBackgroundEnteringArgs);
}
This code is part of the Windows Template Studio. The original file can be found here: SuspendAndResumeService.cs
The translated code in VB.Net:
Public Event OnBackgroundEntering As EventHandler(Of OnBackgroundEnteringEventArgs)
Public Async Function SaveStateAsync() As Task
Dim suspensionState As New SuspensionState With {.SuspensionDate = DateTime.Now}
Dim target = OnBackgroundEntering?.Target.GetType()
Dim onBackgroundEnteringArgs = New OnBackgroundEnteringEventArgs(suspensionState, target)
RaiseEvent OnBackgroundEntering(Me, onBackgroundEnteringArgs)
Await ApplicationData.Current.LocalFolder.SaveAsync(stateFilename, onBackgroundEnteringArgs)
End Function
I have problem with this part:
Dim target = OnBackgroundEntering?.Target.GetType()
The Intellisense show the following error:
Error BC32022 'Public Event OnBackgroundEntering As EventHandler(Of OnBackgroundEnteringEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
I would appreciate if anyone could help me. Thanks.