Hello and Greetings!
For the first time I wanted to try ASP.NET and was looking for SignalR methods to send message to another Webpage using a Visual Studio and C# Application. I found a great Source and I wanted to convert the Application Code from C# to VBNET but there is a few spots that I am not familiar with which throws an error.
The part that I am getting the errors starts with "Await".! I know that the "Awaits" mthod it not used in VBNET 2010, but I tried using "Threading" and other Functions to get a close result, but i failed!
Is there any other way to use a vBNET method for the code? If Yes, then I hope someone could assist me with it.
This the C# Code :
And the part below is where I get the errors, converted to vbnet VBNET:
The RED colored text is where the 3 errors appears. And so far its only the "Await" Part. Crossing my fingers for some fix.
Thanks a lot in advance......
For the first time I wanted to try ASP.NET and was looking for SignalR methods to send message to another Webpage using a Visual Studio and C# Application. I found a great Source and I wanted to convert the Application Code from C# to VBNET but there is a few spots that I am not familiar with which throws an error.
The part that I am getting the errors starts with "Await".! I know that the "Awaits" mthod it not used in VBNET 2010, but I tried using "Threading" and other Functions to get a close result, but i failed!
Is there any other way to use a vBNET method for the code? If Yes, then I hope someone could assist me with it.
This the C# Code :
Code:
namespace ChatAppWinform
{
public partial class ChatForm : Form
{
private HubConnection _connection;
private IHubProxy _myHub;
public ChatForm()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
_connection = new HubConnection("WEBPAGE-OF-CHAT-HERE");
_myHub = _connection.CreateHubProxy("ChatHub");
}
private async void btnSend_Click(object sender, EventArgs e)
{
var gravatar = GravatarHelper.GetGravatar(txtName.Text);
await _myHub.Invoke("Send", JsonConvert.SerializeObject(new MessageSent
{
messageVal = txtMessageSend.Text,
userName = txtName.Text,
id = Guid.NewGuid().ToString(),
text = txtMessageSend.Text,
author = txtName.Text.Split('@').First(),
gravatar = gravatar
}));
}
private async void ChatForm_Load(object sender, EventArgs e)
{
await _connection.Start();
await _myHub.Invoke("Join");
_myHub.On("recieved", data =>
{
var obj = JsonConvert.DeserializeObject<MessageSent>(data);
txtMessage.Text += "USER:" + obj.author + " MESSAGE:" + obj.text + "\n";
});
}
}
}
And the part below is where I get the errors, converted to vbnet VBNET:
Code:
Private Sub ChatForm_Load(ByVal sender As Object, ByVal e As EventArgs)
Await(_connection.Start())
Await(_myHub.Invoke("Join"))
_myHub.[On]("recieved", Function(data)
Dim obj = JsonConvert.DeserializeObject(Of MessageSent)(data)
txtMessage.Text += "USER:" + obj.author + " MESSAGE:" + obj.text + vbLf
End Function)
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim gravatar = GravatarHelper.GetGravatar(txtName.Text)
Await _myHub.Invoke("Send", JsonConvert.SerializeObject(New MessageSent() With { _
Key .messageVal = txtMessageSend.Text, _
Key .userName = txtName.Text, _
Key .id = Guid.NewGuid().ToString(), _
Key .text = "WinForm - " + txtMessageSend.Text, _
Key .author = txtName.Text.Split("@"C).First(), _
Key .gravatar = gravatar _
}))
End Sub
Thanks a lot in advance......