我们开发WinFrom程序,很多时候都希望程序只有一个实例在运行,避免运行多个同样的程序,一是没有意义,二是容易出错. 为了更便于使用,笔者整理了一段自己用的代码,可以判断程序是否在运行,只运行一个实例,而且能实现当程序在运行时,再去双击程序图标,直接呼出已经运行的程序. 下面看代码,只需在程序的入口文件中加如下代码即可: static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] s
一.压缩指定目录下的文件并删除原文件 #!/bin/bashZIP_DAY=7 function zip { local dir=$1 if [ -d $dir ];then local file_num=`ls -l $dir |grep "^d"|wc -l` if [ $file_num -ge $ZIP_DAY ];then local tar_name=`ls -lt $dir | grep -v *.tar.gz | grep -v total | head -n 1 |a
一.进程:需要有用Process类用法一:Process.Start("calc");(不好用)该方法弊端:有许多程序不知道它的运行名字到底是什么,如果写错了,就会出现程序崩溃错误用法二://实例化进程类Process p = new Process();//创建进程开启路径对象ProcessStartInfo psi = new ProcessStartInfo(textBox1.Text);//进程类开启路径指向p.StartInfo = psi;//启动进程,不是立刻开启,什么时
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Diagnostics; using System.Windows.Forms; namespace WindowsFormsApplication3 { pub