小编Joh*_*rar的帖子

如何知道外部申请是否已关闭?

如果一个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进程是否实际关闭而不是总是循环以查看它是否存在?

.net c# winforms

4
推荐指数
1
解决办法
1353
查看次数

检测另一个进程中的特定窗口何时打开或关闭

因此,我制作了一个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)

.net c# winforms

4
推荐指数
1
解决办法
3658
查看次数

使用c#仅从文件夹中移动第一个.txt文件

简单的问题,我知道你可以使用FileMove从一个路径文件移动到another.My问题是,你如何从一个完整的任何类型的文件(的文件夹移动.mp3,.txt,.avi)只有第一个 .txt文件夹,从1到文件夹2?

c#

2
推荐指数
1
解决办法
142
查看次数

为什么File.Move没有按预期工作?

我试图将所有文件移动rootFolderPathdestinationPath

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从我的根文件夹中移动到同一个文件夹中.我没有得到什么东西?

c#

0
推荐指数
1
解决办法
1315
查看次数

标签 统计

c# ×4

.net ×2

winforms ×2