Windows 8.1 开发过程中遇到的小问题(2)
又是在Windows 8.1 的分享功能,再次出现错误:
A COM call (IID: ***, method index: *) to an ASTA (thread *) was blocked because the call chain originated in or passed through another ASTA (thread *). This call pattern is deadlock-prone and disallowed by apartment call control.
Additional information: A COM call to an ASTA was blocked because the call chain originated in or passed through another ASTA. This call pattern is deadlock-prone and disallowed by apartment call control.
A COM call (IID: {*}, method index: *) to an ASTA (thread *) was blocked because the call chain originated in or passed through another ASTA (thread *). This call pattern is deadlock-prone and disallowed by apartment call control.
问题代码,红色部分是错误源:(作为分享目标应用,接受分享进来的文件的代码:例如,用photo应用分享图片)
else if (containsStorageFileFormat)
{
try
{
var items = await operation.Data.GetStorageItemsAsync();
Windows.Storage.StorageFile sf = items[] as Windows.Storage.StorageFile;
if (sf.FileType == ".jpg" || sf.FileType == ".png" || sf.FileType == ".gif")
{
using (IRandomAccessStreamWithContentType ras = await sf.OpenReadAsync())
{
ras.Seek();
if (vm.UploadImage == null)
vm.UploadImage = new BitmapImage();
vm.UploadImage.SetSource(ras);
using (System.IO.Stream stream = ras.AsStreamForRead())
{
stream.Seek(, SeekOrigin.Begin);
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
stream.CopyTo(memStream);
memStream.Position = ; vm.SetImageRelative(memStream, "ShareImage.jpg", ras.ContentType, true);
}
}
}
}
}
catch (Exception e2)
{
WeiboForWin8.Tools.MainProjectTool.HandleException(e2, "ShareTargetView.OnNavigatedTo_2");
vm.UploadImage = null;
}
}
以下是来自http://www.tuicool.com/articles/Rjmeay 帖子中对ASTA 和 STA 的描述,
“Application Single Threaded Apartment” (ASTA).
MSDN Reference on Application Single Threaded Apartments
Which, essentially says that an ASTA is an STA that you can’t create yourself and which doesn’t allow re-entrancy.
也就是说,线程访问出现了问题,后把此行代码改为异步调用:
else if (containsStorageFileFormat)
{
try
{
var items = await operation.Data.GetStorageItemsAsync();
Windows.Storage.StorageFile sf = items[] as Windows.Storage.StorageFile;
if (sf.FileType == ".jpg" || sf.FileType == ".png" || sf.FileType == ".gif")
{
IRandomAccessStreamWithContentType ras = null;
await Task.Run(async() =>
{
ras = await sf.OpenReadAsync();
});
if (ras != null) {
ras.Seek();
if (vm.UploadImage == null)
vm.UploadImage = new BitmapImage();
vm.UploadImage.SetSource(ras);
using (System.IO.Stream stream = ras.AsStreamForRead())
{
stream.Seek(, SeekOrigin.Begin);
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
stream.CopyTo(memStream);
memStream.Position = ; vm.SetImageRelative(memStream, "ShareImage.jpg", ras.ContentType, true);
}
}
}
}
}
catch (Exception e2)
{
WeiboForWin8.Tools.MainProjectTool.HandleException(e2, "ShareTargetView.OnNavigatedTo_2");
vm.UploadImage = null;
}
}
大功告成。
我在做share target的功能的时候,发现很多问题,比如:应用程序未启动或被结束进程时,分享中的某些方法调用正常,但程序在进程中时会发生异常,反之也会有异常,可能是某些方法调用的机制不同(未启动时只能通过COM?),因此,大家一定要在做此功能的时候注意代码的调式和错误处理,尽管很繁琐(调式share简直就是一种煎熬)
Windows 8.1 开发过程中遇到的小问题(2)的更多相关文章
- Windows 8.1 开发过程中遇到的小问题
最近在开发Windows 8 应用的时候碰到了一个莫名的问题,错误内容如下:(其中 **.DLL是本地创建的项目,在主项目中添加了引用,其中大部分代码是MVVM light 框架库的代码) Syste ...
- asp.net mvc开发过程中的一些小细节
现在做网站用mvc越来越普及了,其好处就不说了,在这里只记录一些很多人都容易忽视的地方. 引用本地css和js文件的写法 这应该是最不受重视的地方,有同事也说我有点小题大作,但我觉得用mvc还是得有一 ...
- JAVA开发过程中的各种小坑
1.有时候你在本地跑的ECLIPSE中得到的正确的结果,部署到服务器上使用其他容器,如tomcat或WARS的时候,跑出的结果也许就不一致, 我们程序员会经常抱怨,在我机器上跑的好好的. 在不同的容器 ...
- net+Oracle开发过程中遇到的小问题
最新的项目开始使用Oracle后,5个月之间遇到一些在SqlServer中没有遇到的问题,这里记录并贴上一些常用的解决办法. Oracle相关 一.数据库不同版本还原: 刚开始我们一直使用Oracle ...
- 小程序开发过程中常见问题[微信小程序、支付宝小程序]
目录 一.样式中如何使用background-image呢? 二.使用自适应单位rpx类似于rem,布局尽量使用flex布局 三.万能的{{双大括号,用于在模版中输出变量 四.你想要的基础组件和API ...
- android开发过程中遇到的小问题
转自:http://www.sctarena.com/Article/Article.asp?nid=50701.在编写xml布局的时候,总是提示[Accessibility] Missing ...
- Windows 8.1 Update中的小改变
在Build 2014大会中,发布了Windows 8.1 Update的更新,并将于4月8日通过Windows Update进行推送.但是,在MSDN订阅下载中,带有该更新的镜像已经可以在4月3号放 ...
- 小程序红包开发跳坑记 微信小程序红包接口开发过程中遇到的问题 微信小程序红包开发
现在做小程序的越来越多,商家推广也是一个瓶颈,谁不发点红包,都很难找到人来用你的微信小程序了.于是不管你开发什么小程序功能,你或多或少都要用到小程序来发红包吧. 我们自己之前做公众号发红包,做了两三 ...
- 在WePY中实现了小程序的组件化开发,组件的所有业务与功能在组件本身实现,组件与组件之间彼此隔离,上述例子在WePY的组件化开发过程中,A组件只会影响到A所绑定的myclick
wepyjs - 小程序组件化开发框架 https://tencent.github.io/wepy/document.html#/?id=%e5%be%ae%e4%bf%a1%e5%b0%8f%e7 ...
随机推荐
- 查看真机的APP沙盒文件
1.Xcode --> window --> devices -->左边选择设备 右下边选择要查看的app 双击应用可查看目录 点击设置按钮,选 Download Container ...
- 解决方法:An error occurred on the server when processing the URL. Please contact the system administrator
在WINDOWS7或SERVER2008上安装了IIS7.5,调试ASP程序时出现以下错误: An error occurred on the server when processing the U ...
- man curl_global_init(原创)
curl_global_init(3) libcurl 手册 curl_global_init(3) 名称 curl_global_init - lib ...
- DataGridView的DataGridViewComboBoxColumn列在编辑时自动弹出下拉列表
在DataGridView的CellEnter的事件中添加如下代码即可: if (e.ColumnIndex == dataGridView1.Columns["仓库名"].Ind ...
- css2选择器
CSS1&2元素选择器 选择符 类型 版本 简介 * 通配选择符 CSS2 所有元素对象. E 类型(HTML)选择符 CSS1 以文档语言对象类型作为选择符. E#myid id选择符 ...
- mormot THttpApiServer使用例子
mormot THttpApiServer使用例子 THttpApiServer封装了WINDOWS的HTTPS.SYS. unit Unit1; interface uses Winapi.Wind ...
- 未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=n
这个可能是因为,缺少文件ICSharpCode.SharpZipLib.dll文件. 我从网上下载了个dll文件,放到根目录中自己好了.
- Android入门
在学Android,摘自<第一行代码——Android> 布局管理 通过xml文件进行布局管理. android:id="@+id/button_1" 为当前的元素定义 ...
- 用c语言写的简单计算器
这是自己在学习C语言,凭借自己的兴趣,将课本的知识运用后整理的关于C语言计算器的代码.计算器实现的功能有:加.减.乘.除.求余.功能简单,但对于初学者的我来说能把它写出来,排除每个错误依旧是个难题.前 ...
- win10使用Composer-Setup安装Composer以及使用Composer安装Yii2最新版
1:下载 ca-bundle.crt和cacert.pem 将这两个文件放在php目录下 2:php.ini中添加上述两个文件的路径 curl.cainfo=C:/xampp/php/ca-bundl ...