G
gaxjyxq
Guest
I found the source code from
emoacht/DesktopToast
And I tested the DesktopToast.WinForms code, it worked well.
I want to use the code in VB.NET for Win32 Desktop Form, referenced the "DesktopToast.dll", and convert to the code below.
//////////////////////////////////////////////////////////////////////////
Private Sub Button_ShowToast_Click(sender As Object, e As EventArgs) Handles Button_ShowToast.Click
TextBox_ToastResult.Text = ""
TextBox_ToastResult.Text = Await ShowToastAsync
End Sub
Private Async Function ShowToastAsync() As Task(Of String)
Dim request = New ToastRequest With {
.ToastTitle = "DesktopToast WinForms Sample",
.ToastBodyList = {"This is a toast test.", "Looping sound will be played."},
.ToastAudio = DesktopToast.ToastAudio.LoopingCall,
.ShortcutFileName = "DesktopToast.WinForms.lnk",
.ShortcutTargetFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location,
.AppId = "DesktopToast.WinForms"
}
Dim result = Await ToastManager.ShowAsync(request)
Return result.ToString()
End Function
///////////////////////////////////////////////////////////////////////////////////
But the line below is not right.
TextBox_ToastResult.Text = Await ShowToastAsync
If I used ShowToastAsync,it can work. How to convert the line "TextBox_ToastResult.Text = await ShowToastAsync();"
The C# code is below.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private async void Button_ShowToast_Click(object sender, EventArgs e)
{
TextBox_ToastResult.Text = "";
TextBox_ToastResult.Text = await ShowToastAsync();
}
private async Task<string> ShowToastAsync()
{
var request = new ToastRequest
{
ToastTitle = "DesktopToast WinForms Sample",
ToastBodyList = new[] { "This is a toast test.", "Looping sound will be played." },
ToastAudio = DesktopToast.ToastAudio.LoopingCall,
ShortcutFileName = "DesktopToast.WinForms.lnk",
ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location,
AppId = "DesktopToast.WinForms",
};
var result = await ToastManager.ShowAsync(request);
return result.ToString();
}
}
Continue reading...
emoacht/DesktopToast
And I tested the DesktopToast.WinForms code, it worked well.
I want to use the code in VB.NET for Win32 Desktop Form, referenced the "DesktopToast.dll", and convert to the code below.
//////////////////////////////////////////////////////////////////////////
Private Sub Button_ShowToast_Click(sender As Object, e As EventArgs) Handles Button_ShowToast.Click
TextBox_ToastResult.Text = ""
TextBox_ToastResult.Text = Await ShowToastAsync
End Sub
Private Async Function ShowToastAsync() As Task(Of String)
Dim request = New ToastRequest With {
.ToastTitle = "DesktopToast WinForms Sample",
.ToastBodyList = {"This is a toast test.", "Looping sound will be played."},
.ToastAudio = DesktopToast.ToastAudio.LoopingCall,
.ShortcutFileName = "DesktopToast.WinForms.lnk",
.ShortcutTargetFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location,
.AppId = "DesktopToast.WinForms"
}
Dim result = Await ToastManager.ShowAsync(request)
Return result.ToString()
End Function
///////////////////////////////////////////////////////////////////////////////////
But the line below is not right.
TextBox_ToastResult.Text = Await ShowToastAsync
If I used ShowToastAsync,it can work. How to convert the line "TextBox_ToastResult.Text = await ShowToastAsync();"
The C# code is below.
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private async void Button_ShowToast_Click(object sender, EventArgs e)
{
TextBox_ToastResult.Text = "";
TextBox_ToastResult.Text = await ShowToastAsync();
}
private async Task<string> ShowToastAsync()
{
var request = new ToastRequest
{
ToastTitle = "DesktopToast WinForms Sample",
ToastBodyList = new[] { "This is a toast test.", "Looping sound will be played." },
ToastAudio = DesktopToast.ToastAudio.LoopingCall,
ShortcutFileName = "DesktopToast.WinForms.lnk",
ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location,
AppId = "DesktopToast.WinForms",
};
var result = await ToastManager.ShowAsync(request);
return result.ToString();
}
}
Continue reading...