草庐IT

process_action

全部标签

c# - 为什么即使进程确实存在,Process.WaitForExit 也会抛出 "no process"异常?

我有一个包含此代码的Windows服务:publicstaticvoidExtractTextInner(stringsource,stringdestination){ProcessStartInfostartInfo=newProcessStartInfo();startInfo.FileName=EXTRACTOR_EXE_FILEPATHstartInfo.Arguments="\""+source+"\"\""+destination+"\"";startInfo.CreateNoWindow=true;startInfo.WindowStyle=ProcessWindowS

c# - 在什么情况下 Process.Start() 方法会返回 false?

来自MSDN:Thereturnvaluetrueindicatesthatanewprocessresourcewasstarted.IftheprocessresourcespecifiedbytheFileNamememberoftheStartInfopropertyisalreadyrunningonthecomputer,noadditionalprocessresourceisstarted.Instead,therunningprocessresourceisreusedandfalseisreturned.尝试这样的事情:varinfo=newProcessStart

c# - 如何使用 Task.Run(Action<T>)

我正在尝试创建一个接受TcpClient连接并在客户端连接后执行任务“ConnectedAction”的方法。我在尝试创建新任务以运行委托(delegate)“ConnectedAction”时收到编译错误。Argument1:cannotconvertfrom'void'to'System.Func'我相信这个错误是因为该方法正在尝试运行“ConnectedAction”方法并将void返回给Task.Run参数。如何让任务运行“ConnectedAction”委托(delegate)?classListener{publicIPEndPointListenerEndPoint{ge

c# - "do"/Action LINQ 运算符有什么计划吗?

这是一个带有foreach循环的简单方法:IEnumerableFieldsToXElements(objectinstance){varfieldElements=newList();foreach(varfieldininstance.GetType().GetFields(instance)){fieldElements.Add(newXElement(field.Name,field.GetValue(instance)));}returnfieldElements;}有点丑。如果LINQ中有一些运算符表示“做某事”(例如,为LINQ语句中的每个选定项执行Action),它看起

c# - 将通用 Action<T> 委托(delegate)添加到列表

是否可以将通用委托(delegate)操作添加到列表集合中?我需要某种用于Silverlight应用程序的简单消息传递系统。更新以下是我真正“想要”的classSomeClass{publicTData{get;set;}//andmore....}classApp{List>>_actions=newList>>();voidAdd(Action>foo){_actions.Add(foo);}}编译器:Thetypeornamespacename'T'couldnotbefound(areyoumissingausingdirectiveoranassemblyreference?

C# Process.MainWindowHandle 总是返回 IntPtr 零

这是我的代码:using(Processgame=Process.Start(newProcessStartInfo(){FileName="DatabaseCheck.exe",RedirectStandardOutput=true,CreateNoWindow=true,UseShellExecute=false})){lblLoad.Text="Loading";intSwitch=0;while(game.MainWindowHandle==IntPtr.Zero){Switch++;if(Switch%1000==0){lblLoad.Text+=".";if(lblLoad

c# - 避免硬编码 Controller 和 Action 名称

ASP.NETMVC似乎鼓励我使用硬编码字符串来引用Controller和操作。例如,在Controller中:returnRedirectToAction("Index","Home");或者,在View中:Html.RenderPartial("Index","Home");我不希望我的代码中到处都是硬编码字符串。我该怎么做才能避免这种情况? 最佳答案 我觉得您想使用强类型重定向。我制作了一个名为RedirectionHelper的静态帮助程序类,它具有以下方法:publicstaticstringGetUrl(Expressi

c# - 什么时候太多 "lambda action"?

我经常发现自己将lambda用作某种“本地函数”,以便通过像这样的重复操作让我的生活更轻松:FuncGetText=(resource)=>this.resourceManager.GetString(resource);FuncFormatF1=(f,o)=>String.Format("{0:F1}{1}",f,o);FuncFormatF2=(f,o)=>String.Format("{0:F2}{1}",f,o);与其一遍又一遍地编写String.Format-thing,我可以愉快地使用FormatF2,例如并节省我自己的时间,当我需要更改格式时,只有一个地方可以进行编辑。特

c# - process.standardoutput.ReadToEnd() 总是空的?

我正在启动一个控制台应用程序,但是当我重定向标准输出时,我总是什么也得不到!当我不重定向它,并将CreateNoWindow设置为false时,我在控制台中正确地看到了所有内容,但是当我重定向它时,StandardOutput。ReadToEnd()始终返回一个空字符串。Processcproc=newProcess();cproc.StartInfo.CreateNoWindow=true;cproc.StartInfo.FileName=Dest;cproc.StartInfo.RedirectStandardOutput=true;cproc.StartInfo.WindowSt

c# - 为什么要在此代码中使用 Action?

嗨我看到以下代码:voidUpdateMessage(stringmessage){Actionaction=()=>txtMessage.Text=message;this.Invoke(action);}为什么在这里使用Action然后调用action?为什么不直接使用txtMessage.Text=message来替换函数体中的代码呢?更新代码的更完整版本,在评论中呈现,在下面复制,带有语法突出显示、缩进等。publicpartialclassForm1:Form{publicForm1(){InitializeComponent();newThread(Work).Start(