无法使用 while 循环发送两个以上的输入值 [英] Unable to send more than two input values using a while loop

查看:24
本文介绍了无法使用 while 循环发送两个以上的输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用相同的 while 循环来实现相同的效果,但它变成了无限循环

I tried using the same while loop to achieve the same but its becoming a infinite loop

Sub Main()
    Dim connection = New HubConnection("http://localhost:8080")

    Dim myHub = connection.CreateHubProxy("myHub")

    connection.Start().Wait()
    Console.ForegroundColor = ConsoleColor.Yellow
    myHub.Invoke(Of String)("Chatter", Console.ReadLine) _
    .ContinueWith(
        Sub(task)
            If task.IsFaulted Then
                Console.WriteLine("Could not Invoke the server method Chatter: {0}", _
                                  task.Exception.GetBaseException())
            Else
                Console.WriteLine("Success calling chatter method")

            End If
        End Sub)

    myHub.On(Of String)("addMessage", _
        Sub(param)
            Console.WriteLine("Client receiving value from server: {0}", param.ToString())
        End Sub)
    Console.ReadLine()
End Sub

你能告诉我一种方法来继续将输入值发送到服务器吗?

Could you point to me a way to keep sending the input values to the server ?

**所做的更改 **

Dim param As String = Console.ReadLine()
    While param <> "Exit"
        Console.WriteLine("Server Sending Value to Client X: {0}", param)
        myHub.On(Of String)("addMessage", _
            'Sub(param)
        Console.WriteLine("Client receiving value from server: {0}", param.ToString())
        'End Sub)
        Console.WriteLine("Enter a value to send to the Client.  Enter 'Exit' to quit")
        param = Console.ReadLine()
    End While
    Console.ReadLine()

但在这一行:myHub.On(Of String)("addMessage", _ ITS THROWING ERROR "EXPRESSION EXPECTED"

but in this line : myHub.On(Of String)("addMessage", _ ITS THROWING ERROR "EXPRESSION EXPECTED"

推荐答案

建议你创建一个消息发送方法,比如:

I suggest you create a message sending method, like:

Public Sub SendMessage(ByVal message as String)
'your code here
End Sub

然后在 while true 循环中调用此方法,检查用户是否想要退出

then invoke this method in a while true loop where you check if the user wants to exit

While True
 Dim input = Console.ReadLine()
 If input <> "break"
   SendMessage(input)
 End If
End While

但如果这是使用 SignalR,我建议您检查 指南.(虽然它是在 C# 中)

But if this is using SignalR, i suggest you check this guide. (It's in C# though)

这篇关于无法使用 while 循环发送两个以上的输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆