1如果获得当前进程的Id用:
Process[] processes = Process.GetProcesses();
foreach(Process process in processes)
{
if(process.ProcessName == "进程名"
{
MessageBox.Show(process.Id);
}
}
Process processes =Process.GetCurrentProcess
//processes.id获得当前进程的ID
2如果获得当前线程的ID用:
Thread.CurrentThread.ManagedThreadId.ToString() (推荐)
//或
AppDomain.GetCurrentThreadId().ToString()
3如果获得当前线程的ID用
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.SystemKey == Key.Return || (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Enter))
{
//添加一个换行字符
textBox1.SelectedText = Environment.NewLine; //光标向前移动一位
textBox1.Select(textBox1.SelectionStart + 1, 0);
e.Handled = true;
}
}
/WPF实现时间
private void label1_Loaded(object sender, RoutedEventArgs e)
{
DispatcherTimer timer =new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 1); //间隔1
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
label1.Content = DateTime.Now.ToString("yyyy年MM月dd日 HH时hh分ss秒");//yyyy年MM月dd日 HH:hh:ss 也可以
}
文件夹传输相关
(1)首先要生成DirectoryInfo类的一个实例对象,然后生成一个FileSystemInfo类型的数组,用来记录指定文件夹中的所有目录及子目录,最后循环访问FileSystemInfo中的文件。
textBox1.Text = folderBrowserDialog1.SelectedPath;
DirectoryInfo DInfo = new DirectoryInfo(textBox1.Text);
FileSystemInfo[] FSInfo = DInfo .GetFileSystemInfos();
for(int i=0;i<FSInfo .length;i++)
{
//将文件显示出来
}