用于将RAPI2
文件从 PC 发送到远程设备。
使用不带 的行时Threads
,它可以正常工作:
RemoteFile.CopyFileToDevice(PdtRemoteDevice, "C:\sample.txt", "\test\sample.txt", True)
但是,当我尝试将该行放在 a 上面时Thread
,它会返回一个错误,即设备未连接。
如何使用RAPI2
's CopyFileToDevice
using 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