0

用于将RAPI2文件从 PC 发送到远程设备。

使用不带 的行时Threads,它可以正常工作:

RemoteFile.CopyFileToDevice(PdtRemoteDevice, "C:\sample.txt", "\test\sample.txt", True)

但是,当我尝试将该行放在 a 上面时Thread,它会返回一个错误,即设备未连接。

如何使用RAPI2's CopyFileToDeviceusing Thread?

不使用Thread会使应用程序看起来像挂起。所以,我认为用户不会喜欢一个说没有响应的应用程序。

我的代码:

Imports System.Devices
Imports System.Devices.RemoteDeviceManager

Public Class FormHome
   Dim PdtRemoteDevice As RemoteDevice
   Dim Devicemanager As New RemoteDeviceManager

   Private Sub ButtonHomeCopyToDevice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonHomeCopyToDevice.Click
      PdtRemoteDevice = Devicemanager.Devices.FirstConnectedDevice

      If PdtRemoteDevice Is Nothing Then
         MessageBox.Show("No Device Connected, Please Try Again")
         Exit Sub
      Else
         Dim Th As Thread
         Th = New Thread(AddressOf UploadDatabase)
         Th.IsBackground = True
         Th.Start()
      End If
   End Sub

   Private Sub UploadDatabase()
      Using PdtRemoteDevice = Devicemanager.Devices.FirstConnectedDevice
         If Not (PdtRemoteDevice Is Nothing) Then
            RemoteFile.CopyFileToDevice(PdtRemoteDevice, "C:\sample.txt", "\test\sample.txt", True)
         End If
      End Using
   End Sub
End Class
4

2 回答 2

0

试试这个,让我知道它是否有效:

Private Sub UploadDatabase()
    Using rdm As New RemoteDeviceManager
        Using d As RemoteDevice = rdm.Devices.FirstConnectedDevice
            If Not (d Is Nothing) Then
                RemoteFile.CopyFileToDevice( _
                    d, "C:\sample.txt", "\test\sample.txt", True)
            End If
        End Using
    End Using
End Sub
于 2015-04-29T07:34:28.920 回答
0

创建一个表单,添加 RAPI2 库作为参考,然后添加两个按钮和以下代码:

Imports System.Devices
Imports System.Devices.RemoteDeviceManager
Imports System.Devices.RemoteDevice
Imports System.Devices.RemoteFile


Public Class Form1
    Dim dev As RemoteDevice
    Dim mgr As New System.Devices.RemoteDeviceManager


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        dev = mgr.Devices.FirstConnectedDevice

        If dev Is Nothing Then
            MsgBox("No device connected")
        Else
            MsgBox("Connected to: " & dev.Name)
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim RAPIfile As RemoteFile

        dev = mgr.Devices.FirstConnectedDevice
        Try
            RAPIfile.CopyFileToDevice(dev, "C:\temp\test1.txt", "\Application\Inventory\test1.txt", True)
        Catch
            MsgBox("error")
        End Try

        RAPIfile = Nothing

    End Sub

End Class
于 2017-11-09T14:55:03.997 回答