Is this the proper use of a mutex?

I have a situation where I might have multiple instances of a program running at once, and it's important that just one specific function not be executing in more than one of these instances at once. Is this the proper way to use a mutex to prevent this from happening? lock (this.GetType()) { _log.Info("Doing Sync"); DoSync(); _log.Info("Sync Completed"); } You said multiple i

这是一个互斥体的正确使用吗?

我有一种情况,我可能同时运行一个程序的多个实例,重要的是只有一个特定的函数不能同时在多个实例中执行。 这是使用互斥锁来防止这种情况发生的正确方法吗? lock (this.GetType()) { _log.Info("Doing Sync"); DoSync(); _log.Info("Sync Completed"); } 你说过一个应用程序的多个实例,所以我们正在讨论两个program.exe的运行,对吧? 锁定语句不会锁定多个程序,只是在程序中。 如果你想要一个真正的Mutex

Creating Win32 events from c#

I'd like create a kernel(aka named events) from C#. Do I have to interop services and wrap the native CreateEvent function or is there already a .NET class that does the job? The function that I need to run should be something like this: hEvent = CreateEvent ( NULL , false , false , "MyCSHARPEvent" ); This should notify all procs that probing forMyCSHARPEvent about the event.

从c#创建Win32事件

我想从C#创建一个内核(又名命名事件)。 我是否必须互操作服务并包装本地CreateEvent函数,还是已经有一个可以完成这项工作的.NET类? 我需要运行的函数应该是这样的:hEvent = CreateEvent(NULL,false,false,“MyCSHARPEvent”); 这应该通知所有探测关于事件的MyCSHARPEvent的过程。 如果需要封装函数,我将如何将SECURITY_ATTRIBUTES结构体从C#转换为win32? 看看EventWaitHandle类。 它从.Net 2.0开始支持,

HACK methods in System.Internal (.net 4.0 on x64)

In the mscorlib of .net 4.0 on x64 there is a class System.Internal that contains three static methods with the suffix _HACK . Does anybody have an idea what the purpose of these methods is? Here is the .NET Reflector output: internal static class Internal { // Methods private static void CommonlyUsedGenericInstantiations_HACK() { Array.Sort<double>(null); Ar

System.Internal中的HACK方法(x64上的.net 4.0)

在x64上.net 4.0的mscorlib中有一个System.Internal类,它包含三个带后缀_HACK静态方法。 有没有人知道这些方法的目的是什么? 这是.NET Reflector输出: internal static class Internal { // Methods private static void CommonlyUsedGenericInstantiations_HACK() { Array.Sort<double>(null); Array.Sort<int>(null); Array.Sort<IntPtr>(null); new Arr

Optimizing C loops to get diagonal of array

The Great God Google has not been forthcoming to me with an explanation for some loop optimization issues. So, in sadness that I have insufficient Google-fu, I turn to you StackOverflow. I'm optimizing a C program for solving a specific system of differential equations. During the course of finding the numerical solution I call a function that sets up a linear system of equations and then

优化C循环以获得数组的对角线

伟大的神谷歌并没有向我提供一些循环优化问题的解释。 所以,在悲伤中我没有足够的Google-fu,我转向你StackOverflow。 我正在优化C程序来解决一个特定的微分方程组。 在找到数值解的过程中,我称之为建立线性方程组的函数,然后是解决它的函数。 在定义线性系统的阵列对角线上的元素访问期间,解决方案功能最初有一个瓶颈。 所以我包含了一个在系统初始化过程中设置的一维数组,它保存了数组沿着对角线的值。 为了娱乐

file renaming problem?

Renaming a file in c#: File.Move(source,Destination); File.Delete(source); It execute successfully, how ever when i try to rename the file again, the system gives this exception: The process cannot access the file because it is being used by another process. i cant find that where is this in use? when i further debug the error it shows me the class name is in the process of w3wp.e

文件重命名问题?

在c#中重命名文件: File.Move(source,Destination); File.Delete(source); 它成功执行,当我再次尝试重命名文件时,系统给出此异常: 进程无法访问该文件,因为它正在被另一个进程使用。 我无法找到这个在使用的地方? 当我进一步调试错误时,它显示我的类名是在IIS的w3wp.exe进程中。 接下来我应该做什么? 越来越 foreach (string folder in folder) { FileSystemItem item = new FileSystemItem(); D

Mathematica .Net/Link in an Asp.Net application

I am using the Mathematica .Net/Link platform to create a web service to format and calculate math problems. However I am unable to get it working. I create it using this code: _Log.IpDebug("Starting the Kernel Link"); if (string.IsNullOrEmpty(_MathLinkArguments)) _InternelKernel = MathLinkFactory.CreateKernelLink(); else _InternelKernel = MathLinkFactory.CreateKernelLink(_MathLinkArgum

Mathematica .Net / Link在Asp.Net应用程序中

我正在使用Mathematica .Net / Link平台创建一个Web服务来格式化和计算数学问题。 然而,我无法得到它的工作。 我使用下面的代码创建它: _Log.IpDebug("Starting the Kernel Link"); if (string.IsNullOrEmpty(_MathLinkArguments)) _InternelKernel = MathLinkFactory.CreateKernelLink(); else _InternelKernel = MathLinkFactory.CreateKernelLink(_MathLinkArguments); _Log.IpDebug("Kernel Link Started"); _Int

How to send email with multiple addresses in C#

I'm trying to send emails using gmail's username and password in a Windows application. However, the following code is sending the mail to only the first email address when I collect multiple email address in my StringBuilder instance. var fromAddress = new MailAddress(username, DefaultSender); var toAddress = new MailAddress(builder.ToString());//builder reference having multiple email

如何在C#中使用多个地址发送电子邮件

我正尝试在Windows应用程序中使用Gmail的用户名和密码发送电子邮件。 但是,当我在我的StringBuilder实例中收集多个电子邮件地址时,以下代码仅将邮件发送到第一个电子邮件地址。 var fromAddress = new MailAddress(username, DefaultSender); var toAddress = new MailAddress(builder.ToString());//builder reference having multiple email address string subject = txtSubject.Text; string body = txtBody.Text; ; var

Return to an already open application when a user tries to open a new instance

This has been a problem that I haven't been able to figure out for sometime. Preventing the second instance is trivial and has many methods, however, bringing back the already running process isn't. I would like to: Minimized: Undo the minimize and bring the running instance to the front. Behind other windows: Bring the application to the front. The language I am using this in is

用户尝试打开新实例时返回到已打开的应用程序

这是我一直未能弄清楚的问题。 防止第二个实例是微不足道的,并且有很多方法,但是,将已经运行的进程取回却不是。 我想要: 最小化:撤销最小化并将正在运行的实例放在最前面。 在其他窗口后面:将应用程序放在前面。 我使用的语言是VB.NET和C#。 我发现这个代码很有用。 它执行现有应用程序的检测和可选激活: http://www.codeproject.com/KB/cs/cssingprocess.aspx 如果您使用.NET,使用内置的.NET功能看起来

Single instance application not starting

I developed a single instance WinForm application using .net 4.5 and a mutex on the Main class. Some user report that they can't start the application because the mutex is already taken. static string guid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value + "-OrientalWave"; public static string GUID { get { return guid; } }

单实例应用程序无法启动

我开发了一个使用.net 4.5的单实例WinForm应用程序,并在Main类上创建了一个互斥体。 某些用户报告他们无法启动应用程序,因为互斥量已被占用。 static string guid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), true)[0]).Value + "-OrientalWave"; public static string GUID { get { return guid; } } [STAThread] static void Main(string[] args)

Single Instance Application OS wide with mutex

Done like described: What is the correct way to create a single-instance application? or http://www.c-sharpcorner.com/UploadFile/f9f215/how-to-restrict-the-application-to-just-one-instance/ The mutex works fine inside the user session. But it doesn't work, when I am switching users. May it be because one user is a domain user and the other user where I start the program is a local u

带有互斥体的单实例应用程序

完成描述如下: 创建单实例应用程序的正确方法是什么? 要么 http://www.c-sharpcorner.com/UploadFile/f9f215/how-to-restrict-the-application-to-just-one-instance/ 互斥量在用户会话内正常工作。 但当我切换用户时,它不起作用。 可能是因为一个用户是一个域用户,而另一个我开始该程序的用户是本地用户? 我还没有测试过它与两个本地用户... 我需要在电脑上只有一个实例。 我预计,互斥体将成为操作系统广