又是在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)的更多相关文章

  1. Windows 8.1 开发过程中遇到的小问题

    最近在开发Windows 8 应用的时候碰到了一个莫名的问题,错误内容如下:(其中 **.DLL是本地创建的项目,在主项目中添加了引用,其中大部分代码是MVVM light 框架库的代码) Syste ...

  2. asp.net mvc开发过程中的一些小细节

    现在做网站用mvc越来越普及了,其好处就不说了,在这里只记录一些很多人都容易忽视的地方. 引用本地css和js文件的写法 这应该是最不受重视的地方,有同事也说我有点小题大作,但我觉得用mvc还是得有一 ...

  3. JAVA开发过程中的各种小坑

    1.有时候你在本地跑的ECLIPSE中得到的正确的结果,部署到服务器上使用其他容器,如tomcat或WARS的时候,跑出的结果也许就不一致, 我们程序员会经常抱怨,在我机器上跑的好好的. 在不同的容器 ...

  4. net+Oracle开发过程中遇到的小问题

    最新的项目开始使用Oracle后,5个月之间遇到一些在SqlServer中没有遇到的问题,这里记录并贴上一些常用的解决办法. Oracle相关 一.数据库不同版本还原: 刚开始我们一直使用Oracle ...

  5. 小程序开发过程中常见问题[微信小程序、支付宝小程序]

    目录 一.样式中如何使用background-image呢? 二.使用自适应单位rpx类似于rem,布局尽量使用flex布局 三.万能的{{双大括号,用于在模版中输出变量 四.你想要的基础组件和API ...

  6. android开发过程中遇到的小问题

    ​转自:http://www.sctarena.com/Article/Article.asp?nid=5070​​1.在编写xml布局的时候,总是提示[Accessibility] Missing ...

  7. Windows 8.1 Update中的小改变

    在Build 2014大会中,发布了Windows 8.1 Update的更新,并将于4月8日通过Windows Update进行推送.但是,在MSDN订阅下载中,带有该更新的镜像已经可以在4月3号放 ...

  8. 小程序红包开发跳坑记 微信小程序红包接口开发过程中遇到的问题 微信小程序红包开发

    现在做小程序的越来越多,商家推广也是一个瓶颈,谁不发点红包,都很难找到人来用你的微信小程序了.于是不管你开发什么小程序功能,你或多或少都要用到小程序来发红包吧.  我们自己之前做公众号发红包,做了两三 ...

  9. 在WePY中实现了小程序的组件化开发,组件的所有业务与功能在组件本身实现,组件与组件之间彼此隔离,上述例子在WePY的组件化开发过程中,A组件只会影响到A所绑定的myclick

    wepyjs - 小程序组件化开发框架 https://tencent.github.io/wepy/document.html#/?id=%e5%be%ae%e4%bf%a1%e5%b0%8f%e7 ...

随机推荐

  1. python(第五步django)

    这是一个关于,web开发的库, 下一步需要重点掌握的是,网页跳转和数据展示,和面向对象的关系的重用的内容 1:目前掌握的是project 的创建,和app的创建, 2:

  2. Python str方法总结

    1.返回第一个字母大写 S.capitalize(...) S.capitalize() -> string 1 2 3 4 >>>a = 'shaw' >>> ...

  3. vc++ basic chapt1

    ______API 和SDK _像c程序可以调用各种函数库一样, windows操作系统提供应用程序编程的接口application programming interface简称API函数. 所以主 ...

  4. ngx.lua中遇到的小问题

    作者: 胡 志伟 分类: ngx_lua, 开发代码 发布时间: 2013-09-26 08:40 ė 6评论关闭 在使用ngx.redirect 到一个新的地址时,错误日志提示: lua entry ...

  5. mysql - 行号

    1. 初始化数据 - 列唯一 DROP TABLE IF EXISTS `sales`; CREATE TABLE `sales` ( `empid` ) NOT NULL, `mgrid` ) NO ...

  6. JSF 嵌套

    <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com ...

  7. php 处理别人直接丢过来的json字符串

    如果 json校验成功  出现莫名其妙的不能decode 就看下转义 最好是直接使用php定界符eof来赋值字符串

  8. python之urllib

    简单的web应用包括使用被称为url(统一资源定位器,uniform resource locator)的web地址 这个地址用来在web上定位一个文档,或调用一个CGI程序来为你的客户端产生一个文档 ...

  9. Codeforces Round #383 _python作死系列

    A. Arpa's hard exam and Mehrdad's naive cheat 题意求1378的n次方的最后一位,懒的写循环节 瞎快速幂 py3 int和LL 合并为int了 def q_ ...

  10. 使用 IntraWeb (40) - 自定义 Session 数据

    修改 UserSessionUnit 单元: unit UserSessionUnit; interface uses IWUserSessionBase, SysUtils, Classes, IW ...