如果一个winform关闭了怎么说呢?
bool isRunning = false;
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains("Notepad"))
{
isRunning = true;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码总是检查进程是否存在,但代码对于我想要它做的很慢.那么有没有办法检查Notepad进程是否实际关闭而不是总是循环以查看它是否存在?
因此,我制作了一个Win应用程序,我希望每当我打开记事本中的“页面设置”并在我关闭记事本时将其关闭时,它都在屏幕前弹出。
我尝试了这个:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("User32", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hWnd, int cmdShow);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsIconic(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
ManagementEventWatcher watcher;
public Form1()
{
InitializeComponent();
var query = new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace WHERE ProcessName = 'Notepad.exe'");
var mew = new ManagementEventWatcher(query) { Query = query };
mew.EventArrived += (sender, args) …Run Code Online (Sandbox Code Playgroud) 简单的问题,我知道你可以使用FileMove从一个路径文件移动到another.My问题是,你如何从一个完整的任何类型的文件(的文件夹移动.mp3,.txt,.avi)只有第一个 .txt文件夹,从1到文件夹2?
我试图将所有文件移动rootFolderPath到destinationPath
try
{
string rootFolderPath = @"D:\Log_siteq\";
if (!Directory.Exists(Path.Combine(@"D:\Log_takaya\" + comboBox1.SelectedItem.ToString())))
{
System.IO.Directory.CreateDirectory(Path.Combine(@"D:\Log_takaya\" + comboBox1.SelectedItem.ToString()));
}
string destinationPath = Path.Combine(@"D:\Log_takaya\" + comboBox1.SelectedItem.ToString() );
string fileTypes = @"*.*";
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, fileTypes);
foreach (string file in fileList)
{
string ext = Path.GetExtension(file);
string destination = Path.Combine(destinationPath,file);
File.Move( file,destination);
MessageBox.Show(file);
MessageBox.Show(destination);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
Run Code Online (Sandbox Code Playgroud)
显然MessageBox.Show(file);显示我的根文件夹路径(正常情况下)但MessageBox.Show(destination);显示我同样的事情.
是什么赋予了?它只是将我file从我的根文件夹中移动到同一个文件夹中.我没有得到什么东西?