我正在尝试使用互斥方法只允许我的应用程序的一个实例运行.也就是说 - 我只想为一台机器上的所有用户提供最多一个实例.我已经阅读了关于这个问题的各种其他线程,解决方案看起来很简单,但在测试中我不能让我的第二个实例不能运行.这是我的代码......
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// check that there is only one instance of the control panel running...
bool createdNew = true;
using (Mutex instanceMutex = new Mutex(true, @"Global\ControlPanel", out createdNew))
{
if (!createdNew)
{
Application.Current.Shutdown();
return;
}
}
base.OnStartup(e);
}
}
Run Code Online (Sandbox Code Playgroud) 我知道以提升权限运行的.NET应用程序无法看到用户的映射驱动器。我也知道有一个注册表黑客可以解决此问题(涉及重新启动)。
我想为这个问题创建一个不同的解决方案。我们的应用程序必须提升运行,并且在很大程度上依赖于用户创建的映射驱动器。我想检测用户拥有的映射驱动器,并从提升的应用程序中映射一个类似的驱动器。
所以问题是:如何从提升的应用程序中检测“正常”用户的映射驱动器?
好的,我已经醒了太久了.生气.请有人告诉我为什么这不起作用.传入的字符串如"201212120600" Substring(0,4)返回"201"而不是"2012".我的大脑在融化.
private DateTime StringToDateTimeUTC(String s)
{
System.Diagnostics.Debug.WriteLine(s);
String syear = s.Substring(0, 4);
System.Diagnostics.Debug.WriteLine(syear);
int year = int.Parse(s.Substring(0, 4));
int month = int.Parse(s.Substring(4, 2));
int day = int.Parse(s.Substring(6, 2));
int hour = int.Parse(s.Substring(8, 2));
int minute = int.Parse(s.Substring(10, 2));
DateTime dt = new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Utc);
return dt;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
201212120600
201