Currently i have a problem that this piece of code gives me a task that is always on waiting for activation status.
public static void GetAvailablePorts(List<string> ports, int timeOut)
{
var selector = SerialDevice.GetDeviceSelector();
var task = DeviceInformation.FindAllAsync(selector).AsTask();
Int64 i = 0;
bool done = false;
while (!done)
{
Debug.WriteLine(String.Format("Index: {0}, State: {1}, Id: {2}", i, task.Status.ToString(), task.Id));
i++;
if(TaskStatus.RanToCompletion == task.Status)
done = true;
}
var devices = task.Result;
foreach (var d in devices)
{
ports.Add(d.Id);
}
}
Here are some debug information while running this piece on my end. Does anyone know what the problem is.
In debug output(the end):
Index: 7496, State: WaitingForActivation, Id: 21
Index: 7497, State: WaitingForActivation, Id: 21
Index: 7498, State: WaitingForActivation, Id: 21
Index: 7499, State: WaitingForActivation, Id: 21
Index: 7500, State: WaitingForActivation, Id: 21
Index: 7501, State: WaitingForActivation, Id: 21
Index: 7502, State: WaitingForActivation, Id: 21
Index: 7503, State: WaitingForActivation, Id: 21
Task window of a different run but should serve the same purpose: Task Window
Update:
If i do this it doesn't go into the continueWith 90% of the time. Bit weird.
var selector = SerialDevice.GetDeviceSelector();
return DeviceInformation.FindAllAsync(selector).AsTask().ContinueWith((Task<DeviceInformationCollection> previous) =>
{
var devices = previous.Result;
foreach (var d in devices)
{
ports.Add(d.Id);
}
string b = "";
});
update 2:
After some time. 15 min? i get this error back:
A COM call (IID: {45180254-082E-5274-B2E7-AC0517F44D07}, method index: 8) to an ASTA (thread 9164) appears deadlocked and was timed out.)
Anyone know what is going on?