使Deley执行EXE [英] making Deley The Execution of a EXE

查看:102
本文介绍了使Deley执行EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经完成了一些数据从一个数据库到另一个数据库的移动.我在应用程序中做了
将其放在Windows Scheduler中.每2分钟执行一次.

当系统开始执行exe时,已经在执行中的该应用程序必须销毁当前执行.我们必须限制应用程序的运行,直到之前的过程结束为止.

该怎么做???


谢谢,
Pal.

Hi All,

I have done some data moving from a DB to Another DB. I did in a Application and
put it in windows scheduler. It will be get executed each 2 mins.

when the system start execute the exe , already that application in execution Current execution has to get destroyed. we have to restrict running the application untill previous process gets over.

how to do this???


Thanks ,
Pal.

推荐答案

使用Monitor.Enter做类似的事情,

do something thing like with Monitor.Enter,

Monitor.Enter((object)dgDevices);
           try
           {
               Dg_Devices.Rows[RowIndex].Cells[ColumnName].Value = (object)DBNull.Value;
               Dg_Devices.Rows[RowIndex].Cells[ColumnName].Value = (object)Cellvalue;
               Dg_Devices.Refresh();
           }
           finally
           {
               Monitor.Exit((object)dgDevices);
           }





否则

请参阅此链接
http://www.yoda.arachsys.com/csharp/threads/deadlocks.shtml [ ^ ]

希望对您有帮助

问候
sarva





otherwise

Refer this link
http://www.yoda.arachsys.com/csharp/threads/deadlocks.shtml[^]

i hope this will help you

regards
sarva


如果我理解正确,则希望将应用程序的执行限制为一个实例.
1)如果要阻止再次运行,可以使用以下命令:

If I understood correctly, you want to limit the execution of the application to one single instance.
1) If you want to prevent running a second one you can use this:

static void Main()
  {
     string mutex_id = "__SincleInstanceApp";
     using (NamedMutex mutex = new NamedMutex(false, mutex_id))
     {
        if (!mutex.WaitOne(0, false))
        {           
           // Allready running
           return;
        }
        // Do stuff
     }
  }



另请参见: C#中的单实例应用 [杀死 [ ^ ]像这样:



See also: Single Instance Application in C#[^]
2) If you want to end the already running instance (might be the wrong approach), you have to search for the other instance, and kill[^] it like this:

Process current = Process.GetCurrentProcess();
    Process[] processes = Process.GetProcessesByName (current.ProcessName);

    foreach (Process process in processes)
    {
        if (process.Id != current.Id)
        {
            process.Kill();
        }
    }


请注意,简单地杀死另一个进程会带来很多可能的问题,只有在没有响应的情况下才应使用它.最好尝试使用进程关闭它. CloseMainWindow(),稍等片刻,然后仅比杀死它.但是您也可以使用其他互斥对象与其他应用程序实例进行通信.


Please note, that simply killing an other process hold a lot of possible issues, it should be used only if it is not responding. Better trying to Close it with process.CloseMainWindow(), wait a while and only than killing it. But you also could communicate with your other application instance using an other mutex for example.


这篇关于使Deley执行EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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