Xamarin表单-在ScanFilesToFolderAsync上抛出TaskCanceledException [英] Xamarin Form - TaskCanceledException thrown on ScanFilesToFolderAsync
问题描述
在我的UWP应用程序中,我正在使用扫描功能.在此应用程序中,用户可以通过选择平板扫描仪或自动进纸器来通过扫描仪扫描文档.现在的问题是,当我尝试对其进行扫描时,出现了一个任务被取消的例外情况.
in my UWP application i am working on scan functionality. in this application user can scan the document through scanner by selecting flatbed or auto feeder.Now problem is when i am trying to scan it gives the en exception a Task was canceled.
请帮助.
先谢谢了. :)
祝你有美好的一天...:)
have a great day... :)
private async void Btnscan_Click(object sender, RoutedEventArgs e)
{
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
folderPicker.FileTypeFilter.Add("*");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
//set the destination folder name for scan images.
DeviceInformationDisplay selectedScanner = CmbScannerList.SelectedItem as DeviceInformationDisplay; // here i got the selected scanner.
// scanner id is := "\\\\?\\ROOT#IMAGE#0000#{6bdd1fc6-810f-11d0-bec7-08002be2092f}"
ScanToFolder(selectedScanner.id, folder);
}
功能扫描到"文件夹
public async void ScanToFolder(string deviceId, StorageFolder folder)
{
try
{
cancellationToken = new CancellationTokenSource();
ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId);
if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Flatbed))
{
var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Flatbed, folder).AsTask(cancellationToken.Token); // through an exception(A Task Was Canceled):(
Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage);
}
}
catch (Exception ex)
{
// here i got the exception.
}
}
已更新:
现在我将DeviceClass设置为ALL.
Now i am set the DeviceClass to ALL.
private void StartWatcher()
{
resultCollection.Clear();
DeviceWatcher deviceWatcher;
deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.All); // set Image scanner to all.
deviceWatcherHelper.StartWatcher(deviceWatcher);
}
在扫描仪列表中运行项目后,我得到了所有连接的设备,在其中获得了我的扫描仪名称,这是:当我尝试传递此名称时,它在imagescanner System.Exception中给出了错误:'HRESULT的异常:0x80210015'表示未找到设备. 现在,我全都使用ImageScanner了,而我在扫描仪列表中什么也没得到.
After run the project in scanner list i got the all connected devices in which i got my scanner name This : when i am trying to pass this name it gives error in imagescanner System.Exception: 'Exception from HRESULT: 0x80210015' means device not found. Now i am chnage all to ImageScanner i got nothing in scanner list.
在扫描仪HP应用程序中,我得到了这个名称.和IT Scan Well :(在扫描仪列表中,我的应用程序中没有此名称.:(
and in scanner HP application i got this name. and IT Scan Well :( in scanner list i don't got this name in my application. :(
在我的电脑设置->设备->扫描仪和打印机上,我得到了这些名称.
on my pc setting -> devices -> scanner and printers i got those name.
推荐答案
将问题的解决方法重写为答案.我在机器上正确运行的代码上进行了测试,并认为该问题很可能是驱动程序问题.这已由OP确认,重新安装驱动程序有助于再次进行扫描.
Rewriting the resolution of the problem as an answer. I tested the code on my machine where it behaved correctly and argued the problem is most likely a driver issue. This has been confirmed by the OP and reinstall of the driver helped make the scanning work again.
这篇关于Xamarin表单-在ScanFilesToFolderAsync上抛出TaskCanceledException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!