未处理的异常会使WCF服务崩溃?

编程入门 行业动态 更新时间:2024-10-07 04:33:26
本文介绍了未处理的异常会使WCF服务崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道未处理的异常是否会WCF服务崩溃。我写了下面的程序,它显示了未处理的异常由WCF服务启动一个线程将使整个WCF服务崩溃。

I want to know whether unhandled exception will make WCF service crash. I have written the following program which shows unhandled exception in a thread started by WCF service will make the whole WCF service crash.

我的问题是,我想确认在线程未处理的异常(由WCF服务启动)是否会使WCF崩溃?我的困惑是我认为WCF应是稳定的服务,因为未处理的异常应该不会崩溃。

My question is, I want to confirm whether unhandled exception in threads (started by WCF service) will make WCF crash? My confusion is I think WCF should be stable service which should not crash because of unhandled exception.

我使用VSTS 2008 + C#+。NET 3.5的开发自承载的Windows服务基于WCF服务。

I am using VSTS 2008 + C# + .Net 3.5 to develop a self-hosted Windows Service based WCF service.

下面是code中的相关部分,

Here are the related parts of code,

namespace Foo { // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config. [ServiceContract] public interface IFoo { [OperationContract] string Submit(string request); } } namespace Foo { // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file. public class FooImpl : IFoo { public string Submit(string request) { return String.Empty; } } } namespace Foo { public partial class Service1 : ServiceBase { public Service1() { InitializeComponent(); } ServiceHost host = new ServiceHost(typeof(FooImpl)); protected override void OnStart(string[] args) { host.Open(); // start a thread which will throw unhandled exception Thread t = new Thread(Workerjob); t.Start(); } protected override void OnStop() { host.Close(); } public static void Workerjob() { Thread.Sleep(5000); throw new Exception("unhandled"); } } }

在此先感谢, 乔治

thanks in advance, George

推荐答案

是的,在一个线程中未处理的异常将下跌过程。

Yes, an unhandled exception in a thread will take the process down.

这个过程将会崩溃:

static void Main(string[] args) { Thread t = new Thread(() => { throw new NullReferenceException(); }); t.Start(); Console.ReadKey(); }

这人会不会:

static void Main(string[] args) { Thread t = new Thread(() => { try { throw new NullReferenceException(); } catch (Exception exception) { Console.WriteLine(exception.ToString()); } }); t.Start(); Console.ReadKey(); }

更多推荐

未处理的异常会使WCF服务崩溃?

本文发布于:2023-11-05 10:25:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会使   异常   未处理   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!