如何将参数传递给Windows服务?

我试图将参数传递给Windows服务。 这是我的代码片段: class Program : ServiceBase { public String UserName { get; set; } public String Password { get; set; } static void Main(string[] args) { ServiceBase.Run(new Program()); } public Program() { this.ServiceName = “Create Users Service”; } protected override void OnStart(string[] args) { base.OnStart(args); String User = UserName; String Pass = Password; try { […]

在转换日期时,方法’ToString’没有重载需要1个参数

我正在尝试将我的Angular ui-Datepicker中的日期保存到我的SQL数据库中。 日期格式为(10-27-2015 12:00 AM),但不会保存。 我尝试使用以下命令将其转换为SQL DateTime格式: DateTime? myDate = form.dteStartDate; string sqlFormattedDate = myDate.ToString(“yyyy-MM-dd HH:mm:ss”); 但是我收到错误“方法’ToString’没有重载需要1个参数.SQL中的字段是’datetime’类型。 非常感谢任何帮助。

如何在.net HttpWebRequest中自动检测/使用IE代理设置

是否可以检测/重用这些设置? 怎么样 ? 我得到的例外是这是连接到http://www.google.com时的例外情况 System.Net.WebException: Unable to connect to the remote server —> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 66.102.1.99:80 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket […]

C# – entity framework – mscorlib.dll中发生未处理的“System.StackOverflowException”类型exception

mscorlib.dll中发生了未处理的“System.StackOverflowException”类型exception 确保没有无限循环或无限递归。 以下代码在此方法成功时调用: internal static List GetProductsSoldByCompany(Guid CompanyID) { var ret = from a in _dbRiv.ProductsSold where a.Company.CompanyId == CompanyID select a; return ret.ToList(); } 在返回时,它调用实体模型并尝试填充所有外键控对象(子对象)。 架构是[1公司有0到多个ProductsSold]。 出于某种原因,对以下代码的调用只会自行级联: [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute(“RIV_Model”, “FK_ProductsSold_Company”, “Company”)] [global::System.Xml.Serialization.XmlIgnoreAttribute()] [global::System.Xml.Serialization.SoapIgnoreAttribute()] [global::System.Runtime.Serialization.DataMemberAttribute()] public Company Company { get { return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference(“RIV_Model.FK_ProductsSold_Company”, “Company”).Value; } set { ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference(“RIV_Model.FK_ProductsSold_Company”, “Company”).Value = value; } } /// /// There […]

如何将double格式化为字符串并在必要时仅显示十进制数字?

我的代码如下: lblFranshizShowInvwNoskhehEdit.Text = string.Format(“{0:n}”, (double)(int.Parse(drDarman[“FranshizDarsad”].ToString()) * Convert.ToInt64(RadNumerictxtPayInvwNoskhehEdit.Text)) / 100); 但是{0:n0}字符串格式强制标签的文本不具有十进制数字, {0:n}字符串格式强制标签的文本具有2个十进制数字(默认)。 在我的场景中,我只想在必要时使用十进制数字/没有舍入它们/我该怎么做?

MVC – 具有多个选择列表的控制器

当他们的模型依赖于大量选择列表时,有没有什么好方法可以让我的控制器更简单? 我尽量保持我的大多数控制器操作尽可能简单(希望不超过10行),但在需要大量下拉菜单的页面上,我的操作通常会超出此范围: public class Model { public IEnumerable AllLocations { get; set; } public IEnumerable TopLocations { get; set; } public IEnumerable AllTemplates { get; set; } public IEnumerable TopTemplates { get; set; } // … } [HttpGet] public ActionResult Index(int id) { var domain = Repository.Get(id); var model = Mapper.Map(item); // any way to […]

C#:“使用”语句与HttpWebRequests / HttpWebResponses

Jon Skeet在我的SOApiDotNet代码(用于pre-alpha Stack Overflow API的.NET库)上发表评论(通过推特 ): @ maximz2005我注意到的一件事就是快速浏览源代码:你没有处理(原文如此)的WebResponses。 FTW“使用”声明。 他表示我需要在“使用”语句中包装这些Web会话。 但是,我对此有一个疑问:我应该从HttpWebRequest开始包装整个事情, 还是应该在“using”语句之外创建WebRequest然后将Response包装在里面 ? 我感觉不同的是,在前者中,两个物体都会被处理掉 – 这是正确的吗? 提前致谢。

加载重命名的C#程序集抛出FileNotFoundException

我有一个C#程序集,由C#应用程序引用。 由于我们的编码标准,有一个规则,调试DLL后缀为“d”(例如ProjectA.dll成为ProjectAd.dll )。 当我将重命名的DLL的引用添加到应用程序时,它会成功构建,但在执行时会抛出FileNotFoundException 。 抛出的错误如下: System.IO.FileLoadException: Could not load file or assembly ‘ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49df7f988e86ed92’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: ‘ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49df7f988e86ed92’ 程序集管理器也会发出警告和错误: WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY […]

C#boolean int转换问题

我正在开发一个交易API(来自交互式经纪人的activex),它有一个叫做的方法: void reqMktDataEx(int tickerId, IContract contract, string generalDetails, int snapshot) 问题在于最后一个参数“int snapshot”,它显然需要一个int输入,它实际上表明交易者是否想要快照市场数据。 所以我想如果我把它设置为非零,那么隐式转换会将这个非零值转换为bool值“true”。 但是,我使用c#连接到这个api。 在此之前一切都很好。 我试过这个: A. void reqMktDataEx(1, AUDUSD, “100”, 0)请忽略前三个参数“1,AUDUSD,”100“”,唯一的问题是最后一个0为int。 我在调试过程中暂停了,信息是:“指定的强制转换无效.Invalidcastexception未处理”和“从数字转换时,数字不能为无穷大”。 在此之后,我了解到c#将1作为bool true处理为0,而将bool作为bool处理错误,根据此Web http://www.dotnetperls.com/convert-bool-int B.我尝试了这个void reqMktDataEx(1, AUDUSD, “100”, Convert.ToInt16(false))我又遇到了类似的错误。 C.我再试一次这个: void reqMktDataEx(1, AUDUSD, “100”, int.Parse(“false”)) 投诉是输入字符串格式不正确。 确保方法参数的格式正确。 MY GUESS:这是C#的内部配置,它不将0视为false,将1视为true。 有什么办法可以解决吗? 首先编辑 正如下面一位专业程序员所怀疑的那样,我在这里为他发布合同类和audusd定义。 提前致谢 namespace InteractiveBrokersTradingSystem { class Contract:TWSLib.IContract { public int conId { […]

非静态方法需要目标C#

我有一个win表单应用程序,其中列表框显示方法(按属性)。 我试图动态调用线程中的方法,使用reflection从列表框的选定值获取方法信息。 但是,当调用Methodinfo.Invoke时,我得到了这个内部exception“非静态方法需要一个目标C#”。 这是我的代码(请记住,我仍然是c#和编程的新手。) private void PopulateComboBox() {//Populates list box by getting methods with declared attributes MethodInfo[] methods = typeof(MainForm).GetMethods(); MyToken token = null; List<KeyValuePair> items = new List<KeyValuePair>(); foreach (MethodInfo method in methods) { token = Attribute.GetCustomAttribute(method, typeof(MyToken), false) as MyToken; if (token == null) continue; items.Add(new KeyValuePair( token.DisplayName, method)); } testListBox.DataSource = items; […]