从C#运行dos命令行?

我试图从命令行提示符运行此命令: “D:\\fiji\\fiji.exe -macro D:\\fiji\\macros\\FFTBatch.ijm –headless” 当我在命令行控制台中键入它时,它工作得很好。 但是,当我试图使它从C#应用程序工作时,它失败了。 我试过跟随,但似乎上面的命令没有以某种方式执行: string fijiCmdText = “D:\\fiji\\fiji.exe -macro D:\\fiji\\macros\\FFTBatch.ijm –headless”; System.Diagnostics.Process.Start(“cmd.exe”, fijiCmdText); 任何人都知道如何改变它的工作? 谢谢。

NotifyIcon的问题在Winforms App上没有消失

我有一个.Net 3.5 C#Winforms应用程序。 它没有这样的GUI,只是一个带有ContextMenu的NotifyIcon。 我试图将NotifyIcon设置为visible = false并将其处理在Application_Exit事件中,如下所示: if (notifyIcon != null) { notifyIcon.Visible = false; notifyIcon.Dispose(); } 应用程序获取括号内的代码,但在尝试设置Visible = false时抛出空引用exception。 我已经阅读了几个地方把它放在表格结束事件中,但是那个代码永远不会被击中(可能因为我没有这样的表格?)。 我在哪里可以放置这些代码以便实际工作? 如果我没有把它放入,我会在托盘中看到烦人的挥之不去的图标,直到你将鼠标移到它上面。 干杯。 编辑 只是额外的东西我注意到了……….. 我在应用程序中使用ClickOnce ………如果我只是通过NotifyIcon上的ContextMenu退出应用程序,则不会记录任何exception。 就在应用程序在此处检查升级后触发Application_Exit事件时… private void CheckForUpdate() { EventLogger.Instance.LogEvent(“Checking for Update”); if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.CheckForUpdate()) { EventLogger.Instance.LogEvent(“Update available – updating”); ApplicationDeployment.CurrentDeployment.Update(); Application.Restart(); } } 这有帮助吗?

ASP.NET Core 2.0 Preview 1:如何使用自定义登录路径设置Cookie身份validation

在ASP.NET Core 2.0中,.UseAuthentication()中间件有一个重大更改,不再允许此处提到的旧语法工作。 新版本似乎在addAuthentication中处理配置,但我无法在任何地方找到有关如何更改指定自定义登录和注销URL的旧代码的任何详细信息。 services.AddAuthentication(o => { // Where can I specify this????? var opt = new CookieAuthenticationOptions() { LoginPath = “/api/login”, LogoutPath = “/api/logout”, }; o.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; o.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; }); 任何帮助,将不胜感激…

日历System.Globalization.GregorianCalendar中不支持字符串表示的DateTime

我只是想将出生日期保存到SQL数据库中,但每次获得新的exception时,数据库字段类型都是datetime。 这是我的代码 usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(), “MM/dd/yyyy”, CultureInfo.InvariantCulture);

C# – For vs Foreach – 巨大的性能差异

我正在对一个算法进行一些优化,该算法在给定的数组中找到大于X的最小数字,但随后ai偶然发现了一个奇怪的差异。 在下面的代码中,“ForeachUpper”在625ms结束,“ForUpper”结束,我相信,几个小时(疯狂地慢)。 为什么这样? class Teste { public double Valor { get; set; } public Teste(double d) { Valor = d; } public override string ToString() { return “Teste: ” + Valor; } } private static IEnumerable GetTeste(double total) { for (int i = 1; i d.Valor), test); Console.WriteLine(“————“); ForUpper(ieTeste.Select(d => d.Valor), test); Console.Read(); } private […]

程序随机获取System.AccessViolationException

好的,所以我在调试时遇到了很多问题。 我正在使用VS2013 Pro和Windows 8.1。 两者都是最新的。 问题是,当我开始调试时,它会抛出此错误的一半时间: System.Windows.Forms.dll中发生了未处理的“System.AccessViolationException”类型exception 附加信息:尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。 它也不是我的代码的错。 我做了一个简单的测试作为例子如下。 请注意,我没有从此应用程序引用System.Windows.Forms。 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List testing = new List(); for(int i =0; i < 50; i++) { testing.Add(i); } for (int i = 0; i < 50; i++) […]

减少位图调色板中颜色数量的最佳方法

我有一个包含很多不同颜色的位图。 但我需要用这种图像制作一个40色或更少颜色的方案。 这就是为什么我需要方法来减少位图调色板中的颜色数量。 我正在使用下面的代码为我的应用程序: using System.Windows.Media.Imaging; //BitmapSource ================================================== //Create palette of requied color. Pay heed to maxColorCount it //can have any value, but PixelFormats supports only 2,4,16 and 256 colors. var myPalette = new BitmapPalette(ConvertBitmap(b) as BitmapSource, 16); newFormatedBitmapSource.DestinationPalette = myPalette; //Set PixelFormats newFormatedBitmapSource.DestinationFormat = PixelFormats.Indexed8; newFormatedBitmapSource.EndInit(); b = BitmapFromSource(newFormatedBitmapSource); 它可以工作,但很多时候我会在较暗的颜色的大部分固体背景上收到带有明亮像素的图像: 我试着自己做:最近的4或9像素(正方形)并混合它。 我还尝试减少位图大小并“拉伸”位图。 最后我试图吸收最近的颜色。 但是我用上面的方法得到的最好的结果。 […]

比较DataView.RowFilter中的日期?

我正在摸索一些相当愚蠢而又显然很难的东西。 DataView dvFormula = dsFormula.Tables[0].DefaultView; dvFormula.RowFilter = “‘” + startDate.ToString(“yyyyMMdd”) + “‘ < EndDate OR EndDate = '19000101'"; dvFormula.Sort = "FromDate ASC"; 结果如下: 无法对System.String和System.DateTime执行'<'操作。 请告诉我解决这个问题的最佳方法是什么。 非常感激!

序列化HashSet

我正在尝试序列化Hashset,但我没有运气。 每当我尝试打开序列化数据时,我都会得到一个空的HashSet。 但是,List工作正常。 示例代码: [Serializable()] public class MyClass : ISerializable { public MyClass(SerializationInfo info, StreamingContext ctxt) { HashSet hashset = (HashSet)info.GetValue(“hashset”, typeof(HashSet)); List list = (List)info.GetValue(“list”, typeof(List)); Console.WriteLine(“Printing Hashset:”); foreach (string line in hashset) { Console.WriteLine(line); } Console.WriteLine(“Printing List:”); foreach (string line in list) { Console.WriteLine(line); } } public void GetObjectData(SerializationInfo info, StreamingContext ctxt) { […]

inheritanceList 来实现集合是个坏主意吗?

我曾经读过Imaar Spaanjars关于如何构建3层应用程序的文章。 ( http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1 )这已成为我编码的基础。 因此,我通过inheritanceList实现集合。 因此,如果我有一个名为Employee的类,要实现一个集合,我还将有一个Employees类,如下所示。 class Employee { int EmpID {get;set;} string EmpName {get;set;} } class Employees : List { public Employees(){} } 我从未真正质疑这一点,因为它为我做了工作。 但是现在我开始尝试一些事情,我不确定这是否是正确的方法。 例如,如果我想从Employees获得一个子集,例如 Employees newEmployees = (Employees) AllEmployees.FindAll(emp => emp.JoiningDate > DateTime.Now); 这会抛出System.InvalidCastException。 但是,如果我使用以下内容,则没有问题。 List newEmployees = AllEmployees.FindAll(emp => emp.JoiningDate > DateTime.Now); 那么如何实现Employees以便我不必在DAL或BLL中明确使用List ? 或者我怎样摆脱InvalidCastexception?