使用RAPI2
将文件从PC发送到远程设备。
使用不带Threads
的行时,它可以正常工作:
RemoteFile.CopyFileToDevice(PdtRemoteDevice, "C:\sample.txt", "\test\sample.txt", True)
但是当我尝试将该行放在Thread
内时,它会返回设备未连接的错误。
如何使用线程使用RAPI2
的{{1}}?
不使用CopyFileToDevice
会使应用程序看起来像挂起。因此,我认为用户不会欣赏那些没有响应的应用程序。
我的代码:
Thread
答案 0 :(得分: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
答案 1 :(得分: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