主程序调用客程序:
方法一:
Process.Start( System.Windows.Forms.Application.StartupPath + "\\SelfUpdate.exe").WaitForExit();
waitforexit()等待当前程序结束,继续执行主程序,"\\“很重要不能忘。
方法二:
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = @"路径\exe的文件名";
info.Arguments = "";
info.WindowStyle = ProcessWindowStyle.Minimized;
Process pro = Process.Start(info);
pro.WaitForExit();
html超链接注意:
<QrCode Code="http://www.XXXX.com/XXX.html?t=w&BussinessType=151&deviceno="></QrCode>
要增加个 转义符号&
日志生成方法:
private static readonly ReaderWriterLockSlim _readerWriterLockSlim
= new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
public static void SaveInfoToLog(string info)
{
string path = DateTime.Now.ToString("yyyyMMdd") + ".txt";
string strLogDir = AppDomain.CurrentDomain.BaseDirectory + "\\LogFiles";
if (!Directory.Exists(strLogDir))
{
Directory.CreateDirectory(strLogDir);
}
_readerWriterLockSlim.EnterWriteLock();
using (StreamWriter sw = new StreamWriter(strLogDir + "\\" + path, true, Encoding.UTF8))
{
sw.WriteLine(info);
}
_readerWriterLockSlim.ExitWriteLock();
}
查看printer方法:
Task.Run(() =>
{
if (!IsPrinterOk(printDocument.PrinterSettings.PrinterName))
{
// failed printing, do something...
var form = new Printmessage();
form.ShowInTaskbar = false;
form.ShowDialog();
Debug.WriteLine($">>>>>>>>>>>>>>>>{Thread.CurrentThread.ManagedThreadId}\t failed.");
}
else
{
Debug.WriteLine($">>>>>>>>>>>>>>>>>>>>>>{Thread.CurrentThread.ManagedThreadId}\t success.");
}
});
private static bool IsPrinterOk(string name, int checkTimeInMillisec = 2000)
{
System.Collections.IList value = null;
do
{
//checkTimeInMillisec should be between 2000 and 5000
System.Threading.Thread.Sleep(checkTimeInMillisec);
// or use Timer with Threading.Monitor instead of thread sleep
using (System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_PrintJob WHERE Name like '%" + name + "%'"))
{
value = null;
if (searcher.Get().Count == 0) // Number of pending document.
return true; // return because we haven't got any pending document.
else
{
foreach (System.Management.ManagementObject printer in searcher.Get())
{
value = printer.Properties.Cast<System.Management.PropertyData>().Where(p => p.Name.Equals("Status")).Select(p => p.Value).ToList();
break;
}
}
}
}
while (value.Contains("Printing") || value.Contains("UNKNOWN") || value.Contains("OK"));
return value.Contains("Error") ? false : true;
}
///控制台字体问题
Console.OutputEncoding = System.Text.Encoding.Unicode;