quamotion/madb

Does anyone know how to wait AdbServer.Intance.StartServer() start complete before use AdbClient intance ?

phamgiahung1368 opened this issue · 4 comments

I have a problem when use AdbServer.Intance.StartServer() to start adb.exe when my application startup, sometime it throw an exeption System.Net.Sockets.SocketException: 'No connection could be made because the target machine actively refused it 127.0.0.1:5037' if i use Adbclient instance ( like click on a button and get all devices ) because i dont know when it start completely and ready to use.

  • I use AdbServer.Intance.StartServer() to start adb server but it block main thread of my application to run adb.exe ( my application freeze in that mean time ) and not return StartServerResult enum until i manually kill adb.exe with task manager.

  • I try to run it on a new threadpool thread with async - await and Task.Run() method and it seem to be working good but it still not return StartServerResult enum until i kill adb.exe with task manager. ( my application not freeze in this situation but i dont know whether adb.exe start success or not and when adb.exe start completely and ready to use if it start success )

Why it not run asynchronous on another threadpool thread and return StartServerResult enum after adb.exe start successful ? so that , we can wait for it start completely before use Adbclient instance to manipulate with device.

Sorry about my english , it not my native language :D

you need to start server (Not byAdbServer.Intance.StartServer())
AdbServer server= New AdbServer;
//adbpath is adb.exe location
server.StartServer(adbpath, False);

then start DeviceMonitor
DeviceMonitor Devmonitor= New DeviceMonitor(New AdbSocket(New IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
Devmonitor.Start();
and you can get devices Or run Other command

But I also have a problem with the freeze which is related to the status of the device.#156
But normally, there is no problem.

@iliyasoori you can try async await functioning in c#, it can avoid freezing the app when adb server start.

@netifork thanks
await for what? DeviceMonitor cannot start if device connect unauthorized mode!
Can you give an example? i programming with vb.net.

@iliyasoori you can try async await functioning in c#, it can avoid freezing the app when adb server start.

How?