我正在尝试将此C#代码翻译为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);
}
此代码是Windows Template Studio的一部分。原始文件可在此处找到:SuspendAndResumeService.cs
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
我对这部分有疑问:
Dim target = OnBackgroundEntering?.Target.GetType()
Intellisense显示以下错误:
错误BC32022'公共事件OnBackgroundEntering As EventHandler(Of OnBackgroundEnteringEventArgs)'是一个事件,无法调用 直。使用'RaiseEvent'语句来引发事件。
如果有人能帮助我,我将不胜感激。感谢。