如何在C#中处理actvie和非活动进程 [英] How to handle actvie and non-active processes in C#

查看:80
本文介绍了如何在C#中处理actvie和非活动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,





我正在运行一个exe(SBM Mail.exe,它是C#windows apps)。但在Form Load事件发生之前,我想检查SBM Mail.exe是否已经运行。如果正在运行并且它处于活动状态意味着它不应该允许另一个同名进程(即SBM Mail.exe)。



另外我想查看当前正在运行的活动进程。



请帮我解决这个问题。




I am running an exe(SBM Mail.exe which is C# windows apps). But at the same time before Form Load event i want to check whether SBM Mail.exe is been already running or not. If running and it is active means it should not allow another process of same name(i.e.,SBM Mail.exe).

Also i want to check currently running active processes.

Kindly please help me to solve this.

推荐答案

你可以使用 GetProcessByName [ ^ ]。但我很确定在表单层面处理此类任务并不明智。因为您的应用程序可能会有许多并发用户,所以您更有可能需要在应用程序级别上处理此问题。这是一个其他设计问题,您在服务器端使用常规应用程序作为后台工作程序,而不是服务 - 问题不是您使用它,问题是您需要如何处理它。
You can get a process using GetProcessByName[^]. But I am pretty sure that it is not wise to handle such tasks on form level. Because you will probably have many concurrent users of your application it is more likely that you need to handle this on application level. It is an other design issue that you use on server side a regular application as background worker, and not a service - and the problem is not that you use it, the problem is how you need to handle it.


为什么要标记你的问题ASP.NET?那令人困惑。

System.Diagnostics.Process.GetProcessesByName 返回一个具有给定名称的进程列表。

但是您的问题也可能允许不同的解释:即您提到的表单加载事件发生在SMB Mail.exe中。在这种情况下,ApplicationFramework是你的朋友:它确保一次只运行一个实例;它可以将命令行参数从稍后调用可执行文件转发到已经运行的进程。
Why did you tag your question "ASP.NET"? That''s confusing.
System.Diagnostics.Process.GetProcessesByName returns a list of processes with a given name.
But your question might also allow for a different interpretation: i.e. the "Form Load" event you mention happens in that "SMB Mail.exe". In that case, the ApplicationFramework is your friend: it makes sure that only one instance is running at a time; and it can forward command line parameters from a later call to the executable to the already running process.


在visual studio中,只需将其作为项目属性中的单实例应用程序。你不必检查任何其他实例正在运行......
In visual studio, just make it as a single instance application in project properties. you dont have to check for any other instance being running at all...


这篇关于如何在C#中处理actvie和非活动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆