c# 程序只运行一次的处理方法
方法一:遍历正在有相同名字运行的例程
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DHPSS.COM
{
/// <summary>
/// c#程序只运行一次,C#例程只运行一次
/// http://blog.csdn.net/nnsword
/// QQ:16349023
/// </summary>
public class CHandleRunningPro
{
/// <summary>
/// const int, ShowWindowAsync 使用时的参数,让窗体正常显示确保没有隐藏和最小化。
/// </summary>
private const int WS_SHOWNORMAL = 1;
/// <summary>
/// 功能:遍历所有运行的例程,判断是否已经有相同名字的例程。
/// 实现:遍历所有运行的例程,如果有与自己名字相同的比较 ID 是否相同。
/// 如果ID不同说明已经有实例在运行,则把该实例返回。
/// 如果没有则返回 null
/// </summary>
/// <returns>有相同名字的例程返回其 process,否则返回null</returns>
private Process GetRunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
//遍历正在有相同名字运行的例程
foreach (Process process in processes)
{
//忽略现有的例程
if (process.Id != current.Id)
{
return process;
}
}
//没有其它的例程,返回Null
return null;
}
//接下来调用两个WinAPI,其功能将在包装方法中描述,
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
//以上的方法声明为私有,对其进一步包装,
相关文档:
/**************************************************************************************************
* 作者wenwenhua
*
/* Program : A Simple Screen Saver
* File Name : ScreenSaver.cs
* Author : Tran Khanh Hien
......
本文将介绍C#项目打包以及自动安装SQL Sever数据库,包括创建部署项目、将主程序项目的输出添加到部署项目中、创建安装程序类、创建自定义安装对话框等等。
’power by: landlordh
’for 2000,xp,2003
Module uninstall
Sub Main ......
参考《ASP.NET与SQL一起打包部署安装》
,这篇文章是针对VB.NET与SQL 一起打包的,但是我使用的是C#,当然只要修改一下主要安装类库就行了!C#的类库代码如下:DBCustomAction.cs
using System;
using System.Collections;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Configuration.Inst ......
ed2k://|file|[ReadFree]_C#.开发人员指南——ASP_NET、XML、web服务与.ADO_NET_11030729.rar|6563070|B1CBF4D0032C8D78FB10F5F2AE6C3882|/
ed2k://|file|[ReadFree]_C#网络应用编程_11041620.rar|8063056|7044A65903D86BF88BE8AF26D8E02B61|/
ed2k://|file|[ReadFree]_Java.P2P程序设计_11052086.rar|8742852| ......
在C#.net中如何操作XML
在C#.net中如何操作XML
可能很多朋友还没有进行过XML操作,希望下面这篇文章能对大家有帮助.或者自己复制一下代码试一下.这篇文章不是我写的.我只是转过来.觉得不错.
需要添加的命名空间:
using System.Xml;
定义几个公共对象:
XmlDocument xmldoc ;
XmlNode xmlnode ;
XmlElement xmlele ......