连接时间输出

时间:2012-09-19 02:25:35

标签: vb.net winforms

这是一个winforms VB.net应用程序。我最近已经到了需要为应用程序添加远程更新的地步。由于资金的限制,以及我可靠的互联网连接,我认为处理推出更新文件的最佳解决方案只是创建一个免费的电子邮件帐户。连接pop3Client库,然后下载并保存附件,并从那里进一步处理。下面是连接到服务器并保存所需附件的子。

  Public Shared Sub HeadersFromAndSubject(hostname As String, port As Integer, useSsl As Boolean, username As String, password As String, messageNumber As Integer)
    Using client As New Pop3Client
        client.Connect(hostname, port, useSsl)
        client.Authenticate(username, password)
        Dim headers As Header.MessageHeader = client.GetMessageHeaders(messageNumber)
        Dim from As Header.RfcMailAddress = headers.From
        Dim subject As String = headers.Subject
        If from.HasValidMailAddress AndAlso from.Address.Equals("XXXXXXX@XXXX.COM") AndAlso "XXXXX Update".Equals(subject) Then
            Dim message As Message = client.GetMessage(messageNumber)
            For Each attachment As MessagePart In message.FindAllAttachments()
                If attachment.FileName.Equals("XXXXXXUpdateFiles.zip") Then
                    File.WriteAllBytes(attachment.FileName, attachment.Body)
                    Dim FilePath As String = "C:\XXXXX\XXXXXXXXXUpdateFiles.zip"
                    If File.Exists(FilePath) Then
                        File.Delete(FilePath)
                        Dim fileInf As New FileInfo("C:\XXXXXX\" + attachment.FileName)
                        attachment.Save(fileInf)

                    End If
                End If
            Next
        End If
    End Using
End Sub

问题是我在Dim Headers行上收到以下消息......

     A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

这应该是我应该使用的实例:

Application.DoEvents() 

如果是这样,那么实施它的正确方法是什么?如果不是我做错了什么?

0 个答案:

没有答案