线程中的exception处理

最近我参加了一次采访。 给我一个代码片段。我知道,面试官是从albhari的线程样本中获取的。 public static void Main() { try { new Thread (Go).Start(); } catch (Exception ex) { // We’ll never get here! Console.WriteLine (“Exception!”); } } static void Go() { throw null; } 将上述代码修改为 public static void Main() { new Thread (Go).Start(); } static void Go() { try { … throw null; // this exception […]

HttpWebRequest将凭据传递给下一个HttpWebRequest

我正在使用HttpWebRequest登录页面并获取一些信息。 然后我使用该信息创建一个新的HttpWebRequest以获取更多信息。 我不想使用WebClient。 如何将使用第一个HttpWebRequest登录时获得的凭据传递给第二个? 编辑:如果我使用CookieCollection,那么这将是空的。 我只是尝试使用WebClient作为最后的手段,即使它没有工作,第二个请求将我带回登录屏幕。 我注意到在WebBrowser中有一个cookie。

WCFexception处理

如果我的WCF服务中发生exception,那么将该错误传达给客户端的最佳方法是什么? 我应该在服务上登录并重新抛出soapexception吗? 或者我应该记录它并返回用户友好的消息?

在Sql连接字符串中Trusted = yes / no是什么意思?

在Sql连接字符串中Trusted = yes / no是什么意思? 我正在创建一个连接字符串,如下所示: string con= string.Format( “user id=admin;password=admin;server={0};Trusted_Connection=yes;database=dbtest;connection timeout=600”, _sqlServer); 请帮忙

Visual Studio 2017缺少exe文件

(我使用的是Visual Studio 2017) 我开始了一个小型的控制台应用 一个Discord C#bot。 所以我总是用Visual Studio启动这个程序。 完成后,我想将.exe文件放在服务器上,以保持这个机器人整天保持在线状态。 在目录中,没有.exe文件。 所以我再次启动了应用程序,看到这个控制台是从另一个路径打开的 “C:\ Program Files \ dotnet”,此.exe称为“dotnet.exe” 当我想手动启动这个.exe文件时,它立即关闭(可能是因为缺少代码行Console.ReadLine();我不知道)。 有人能告诉我,在Visual Studios设置中要更改什么,在我的控制台应用程序的正确目录中有一个.exe文件? 附图显示了我的bin目录,通常是.exe文件。 有一个.dll文件,但我需要.exe ..

从EF选择返回元组

如何使用EF4在Select中检索元组? var productCount = (from product in context.products select new Tuple(product, products.Orders.Count)); 要么 var productCount = (from product in context.products select Tuple.Create(product, products.Orders.Count)); entity framework说第一种情况不能使用空构造函数,而第二种情况则不能识别Tuple.Create方法。

尝试通过Office 365发送电子邮件时SMTP 5.7.57错误

我正在尝试设置一些代码以通过Office 365经过身份validation的SMTP服务发送电子邮件: var _mailServer = new SmtpClient(); _mailServer.UseDefaultCredentials = false; _mailServer.Credentials = new NetworkCredential(“test.user@mydomain.com”, “password”); _mailServer.Host = “smtp.office365.com”; _mailServer.TargetName = “STARTTLS/smtp.office365.com”; // same behaviour if this lien is removed _mailServer.Port = 587; _mailServer.EnableSsl = true; var eml = new MailMessage(); eml.Sender = new MailAddress(“test.user@mydomain.com”); eml.From = eml.Sender; eml.to = new MailAddress(“test.recipient@anotherdomain.com”); eml.Subject = “Test message”; […]

WPF RichTextBox语法突出显示问题

大家好我一直在研究一个带有文本编辑器的WPF应用程序这个文本编辑器应该应用一些样式或着色一些标记(关键字)来突出显示它并使其显而易见,,,问题是我非常努力但是我仍然得到相同的结果,即用户在关键字被设置样式后输入整个文本中的一个关键字! 试想一下,如果你在“C#”中键入“string”关键字,它之后的整个文字将会变成蓝色。 这是我使用的代码: static List tags = new List(); static List specials = new List(); static string text; #region ctor static MainWindow() { string[] specialWords = { “string”, “char”, “null” }; tags = new List(specialWords); // We also want to know all possible delimiters so adding this stuff. char[] chrs = { ‘.’, ‘)’, ‘(‘, […]

将JSON对象反序列化为C#列表

我正在尝试使用Bill Reiss的教程在C#中反序列化给定的JSON文件。 对于非列表中的XML数据,此方法非常有效,但我希望使用以下结构反序列化JSON文件: public class Data { public string Att1 { get; set; } public string Att2 { get; set; } public string Att3 { get; set; } public string Att4 { get; set; } } public class RootObject { public List Listname { get; set; } } 我的问题是使用JSON.Net创建/将数据放入列表,然后在XAML页面上显示列表的能力。 到目前为止我的想法(这是行不通的): var resp = await client.DoRequestJsonAsync(“URL”); […]

在一个WCF服务中托管多个合同

是否可以在一个WCF服务中托管多个服务合同? 如果是这样,怎么样? 我一直在谷歌搜索和一些post说你可以做(​​但不是如何)和其他人说,这是不可能的。 当我运行服务器时,我收到此错误: 在服务“ConsoleAppWcfServer.FooService”实现的合同列表中找不到合同名称“ConsoleAppWcfCommon.IBarService”。 这是我的服务器代码: static void Main(string[] args) { string serviceAddress = “net.tcp://localhost:8088/FooBarService”; // I’m stuck here as I have to pick *one* service ServiceHost selfServiceHost = new ServiceHost(typeof(FooService)); // I can add both endpoints here, but this is what gives me the error. selfServiceHost.AddServiceEndpoint(typeof(IFooService), new NetTcpBinding(), serviceAddress); selfServiceHost.AddServiceEndpoint(typeof(IBarService), new NetTcpBinding(), serviceAddress); selfServiceHost.Open(); […]