如何使一个WCF服务STA(单线程) [英] How to make a WCF service STA (single-threaded)

查看:296
本文介绍了如何使一个WCF服务STA(单线程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务,其中包括UI组件,这迫使我要在STA模式。

我如何设置服务行为STA-模式?


该服务使用的引用,它会打开一个UI窗口(用于查看端口)进行图像分析WPF DLL文件。当服务试图创建该项目的一个实例(从窗口继承),它抛出一个异常:

  

调用线程必须为STA

解决方案

试用文章的 WCF STA线程 的。它提供了非常明确的指示(和code)在使用WCF和STA线程。

它说明了如何创建一个WCF的行为,让WCF操作在一​​个STA线程中运行。

I have a WCF service which includes UI components, which forces me to be in STA mode.

How do I set the service behaviour to STA-mode?


The service uses a reference to a WPF DLL file which opens a UI window (used as view port) for picture analysis. When the service is trying to create an instance of that item (inherits from window) it throws an exception:

The calling thread must be an STA

解决方案

Try the article WCF STA Threads. It provides very clear instructions (and code) for using WCF and STA threads.

It explains how to create a WCF behaviour to allow WCF operations to run in an STA thread.

这篇关于如何使一个WCF服务STA(单线程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆