- 应用程序 防止 重复开启
bool canCreateNew;
Mutex m_ServerMutex = new Mutex(true, "EMTASS_SERVER", out canCreateNew);
if (canCreateNew) { }
else{ }
-
string类的常用方法:
string.length 计算的值从1开始算
string.indexof("") 从0开始
string.substring(a,b);从第a位开始,取b个字符
string.split(’ ') 以" "为分界将字符串划分为N个数组 -
配置打印机
using System.Threading;
using System.IO;
using System.IO.Ports;
/// <summary>
/// 配置打印机
/// </summary>
///
private void Print(string content)
{
Thread.Sleep(100);
string printTxt1 = "";
string path1 = System.IO.Directory.GetCurrentDirectory();
FileStream tempFile1 = new FileStream(path1 + @"\Text.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamReader tempFileRead1 = new StreamReader(tempFile1, Encoding.GetEncoding("gb2312"));
printTxt1 = tempFileRead1.ReadToEnd();
tempFileRead1.Close();
tempFile1.Close();
SerialPort sp1 = new SerialPort();
sp1.BaudRate = 9600;
sp1.PortName = "COM1"; //使用COM1端口
sp1.Parity = System.IO.Ports.Parity.None;
sp1.DataBits = 8;
sp1.StopBits = System.IO.Ports.StopBits.One;
sp1.Open();
try
{
Thread.Sleep(10);
sp1.WriteLine(printTxt1);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
sp1.Close();
}