又是在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. 国内外著名B2C系统介绍兼比较ASP.NET和PHP

    国内外著名B2C系统介绍兼比较ASP.NET和PHP   2010-06-08 11:44  来源:  我来投稿  我要评论    中介交易 SEO诊断淘宝客 站长团购 云主机 A5外包  国内外著名 ...

  2. 网络请求框架----HttpClient的get,post和图片上传服务器

    HttpClient是Apache Jakarta Common下的子项目,用来提供高效的.最新的.功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议.HttpCli ...

  3. linux档案与文件的的压缩与打包

    本文涉及的命令:gzip.zcat.bzip2.bzcat.tar.dump.restore.mkiosfs.cdrecord.dd.cpio. 概念: 几种基础压缩的概念: 计算机最小单位是字节,但 ...

  4. background-size的两个属性:cover和contain

    两种都不会造成图片失真,其中: (1)cover:相当于宽度等于元素的宽度,高度设为auto: (2)contain:相当于高度等于元素的高度,宽度设为auto: 例如:设置一个高度和宽度都为300p ...

  5. C#委托使用:多播 ,向委托注册多个方法

    private static void EnglishGreeting(string name) { Console.WriteLine("Morning, " + name); ...

  6. workerman 的回调函数

    接下来,记录一下workerman 的回调函数 <?php /** * Created by PhpStorm. * User: zeopean * Date: 2016-08-26 * Tim ...

  7. ng中的过滤器

    angular中对输出的值提供过滤器,用法如下: {{name | currency:"¥"}}</p> 这是在在html中的用法,用 | 来添加过滤器,过滤器后面通过 ...

  8. SMTP的相关命令

    SMTP是Simple Mail Transfer Protocol的简写. 邮件是日常工作.生活中不能缺少的一个工具,下面是邮件收发的流程. Image 邮件的发送,主要是通过SMTP协议来实现的. ...

  9. [C#-SQLite] SQLite一些奇怪的问题

    今天整C#的DAO层,我用的2013, 用的4.0的.NetFramework刚刚创建完Helper就出现异常 +        Connection    "helper.Connecti ...

  10. @gettrcname.sql

    http://www.eygle.com/archives/2007/05/script_gettrcname.html 最近有很多朋友问起<深入浅出Oracle>一书中的一个脚本gett ...