Commit f3c975c4 LN

合并

2 个父辈 d7057027 8953068c
...@@ -10,6 +10,7 @@ using System.Runtime.InteropServices; ...@@ -10,6 +10,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using OnlineStore.DeviceLibrary; using OnlineStore.DeviceLibrary;
using System.IO;
namespace OnlineStore.AssemblyLine namespace OnlineStore.AssemblyLine
{ {
...@@ -114,7 +115,7 @@ namespace OnlineStore.AssemblyLine ...@@ -114,7 +115,7 @@ namespace OnlineStore.AssemblyLine
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() +""+e.ExceptionObject.ToString()+" "); LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() + "" + e.ExceptionObject.ToString() + " ");
} }
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
...@@ -125,12 +126,116 @@ namespace OnlineStore.AssemblyLine ...@@ -125,12 +126,116 @@ namespace OnlineStore.AssemblyLine
static void LogUnhandledException(string type, string exceptionobj) static void LogUnhandledException(string type, string exceptionobj)
{ {
//这里可以进一步地写日志 //这里可以进一步地写日志
string dir = Application.StartupPath + "\\ErrorDump\\";
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string formTitle = ConfigAppSettings.GetValue(Setting_Init.App_Title);
MiniDump.Write(dir + DateTime.Now.ToString("yyyyMMddHHmmss") + $"-{formTitle}.dmp");
LogUtil.error("【" + type + "】" + exceptionobj); LogUtil.error("【" + type + "】" + exceptionobj);
MessageBox.Show(exceptionobj, type); MessageBox.Show(exceptionobj, type);
}
#region dump
public sealed class MiniDump
{
[Flags]
public enum DumpType : uint
{
// From dbghelp.h:
MiniDumpNormal = 0x00000000,
MiniDumpWithDataSegs = 0x00000001,
MiniDumpWithFullMemory = 0x00000002,
MiniDumpWithHandleData = 0x00000004,
MiniDumpFilterMemory = 0x00000008,
MiniDumpScanMemory = 0x00000010,
MiniDumpWithUnloadedModules = 0x00000020,
MiniDumpWithIndirectlyReferencedMemory = 0x00000040,
MiniDumpFilterModulePaths = 0x00000080,
MiniDumpWithProcessThreadData = 0x00000100,
MiniDumpWithPrivateReadWriteMemory = 0x00000200,
MiniDumpWithoutOptionalData = 0x00000400,
MiniDumpWithFullMemoryInfo = 0x00000800,
MiniDumpWithThreadInfo = 0x00001000,
MiniDumpWithCodeSegs = 0x00002000,
MiniDumpWithoutAuxiliaryState = 0x00004000,
MiniDumpWithFullAuxiliaryState = 0x00008000,
MiniDumpWithPrivateWriteCopyMemory = 0x00010000,
MiniDumpIgnoreInaccessibleMemory = 0x00020000,
MiniDumpValidTypeFlags = 0x0003ffff,
};
LogUtil.error("【" + type + "】" + exceptionobj); //typedef struct _MINIDUMP_EXCEPTION_INFORMATION {
// DWORD ThreadId;
// PEXCEPTION_POINTERS ExceptionPointers;
// BOOL ClientPointers;
//} MINIDUMP_EXCEPTION_INFORMATION, *PMINIDUMP_EXCEPTION_INFORMATION;
[StructLayout(LayoutKind.Sequential, Pack = 4)] // Pack=4 is important! So it works also for x64!
struct MiniDumpExceptionInformation
{
public uint ThreadId;
public IntPtr ExceptioonPointers;
[MarshalAs(UnmanagedType.Bool)]
public bool ClientPointers;
} }
//BOOL
//WINAPI
//MiniDumpWriteDump(
// __in HANDLE hProcess,
// __in DWORD ProcessId,
// __in HANDLE hFile,
// __in MINIDUMP_TYPE DumpType,
// __in_opt PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
// __in_opt PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
// __in_opt PMINIDUMP_CALLBACK_INFORMATION CallbackParam
// );
[DllImport("dbghelp.dll",
EntryPoint = "MiniDumpWriteDump",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Unicode,
ExactSpelling = true, SetLastError = true)]
static extern bool MiniDumpWriteDump(
IntPtr hProcess,
uint processId,
IntPtr hFile,
uint dumpType,
ref MiniDumpExceptionInformation expParam,
IntPtr userStreamParam,
IntPtr callbackParam);
[DllImport("kernel32.dll", EntryPoint = "GetCurrentThreadId", ExactSpelling = true)]
static extern uint GetCurrentThreadId();
[DllImport("kernel32.dll", EntryPoint = "GetCurrentProcess", ExactSpelling = true)]
static extern IntPtr GetCurrentProcess();
[DllImport("kernel32.dll", EntryPoint = "GetCurrentProcessId", ExactSpelling = true)]
static extern uint GetCurrentProcessId();
public static bool Write(string fileName)
{
return Write(fileName, DumpType.MiniDumpWithFullMemory);
}
public static bool Write(string fileName, DumpType dumpType)
{
using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.None))
{
MiniDumpExceptionInformation exp;
exp.ThreadId = GetCurrentThreadId();
exp.ClientPointers = false;
exp.ExceptioonPointers = System.Runtime.InteropServices.Marshal.GetExceptionPointers();
bool bRet = MiniDumpWriteDump(
GetCurrentProcess(),
GetCurrentProcessId(),
fs.SafeFileHandle.DangerousGetHandle(),
(uint)dumpType,
ref exp,
IntPtr.Zero,
IntPtr.Zero);
return bRet;
}
}
}
#endregion
static void Test() static void Test()
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.Common</RootNamespace> <RootNamespace>OnlineStore.Common</RootNamespace>
<AssemblyName>Common</AssemblyName> <AssemblyName>Common</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
......
...@@ -140,30 +140,30 @@ namespace OnlineStore.DeviceLibrary ...@@ -140,30 +140,30 @@ namespace OnlineStore.DeviceLibrary
string r = ""; string r = "";
bool eyemNoCode = false; bool eyemNoCode = false;
Task eyemtask = Task.Factory.StartNew(delegate { //Task eyemtask = Task.Factory.StartNew(delegate {
List<CodeInfo> tlci = EyemDecode.ModelDecoder(ref bmp); // List<CodeInfo> tlci = EyemDecode.ModelDecoder(ref bmp);
foreach (CodeInfo code in tlci) // foreach (CodeInfo code in tlci)
{ // {
LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr); // LogUtil.info(deviceName + " 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
string str = CodeManager.ReplaceCode(code.CodeStr); // string str = CodeManager.ReplaceCode(code.CodeStr);
if (!codeList.Contains(str)) // if (!codeList.Contains(str))
{ // {
codeList.Add(str); // codeList.Add(str);
r = r + "##eyem|" + code.CodeType + "|" + str; // r = r + "##eyem|" + code.CodeType + "|" + str;
if (!findRightCode) // if (!findRightCode)
{ // {
findRightCode = HasRightCode(str); // findRightCode = HasRightCode(str);
} // }
} // }
} // }
}); //});
//最多等待60秒 ////最多等待60秒
bool taskResult = eyemtask.Wait(60000); //bool taskResult = eyemtask.Wait(60000);
if (!taskResult) //if (!taskResult)
{ //{
LogUtil.error(deviceName + " 【" + cameraName + "】eyem扫码超时"); // LogUtil.error(deviceName + " 【" + cameraName + "】eyem扫码超时");
eyemNoCode = true; // eyemNoCode = true;
} //}
if (!isPreScan) if (!isPreScan)
{ {
if (!findRightCode) if (!findRightCode)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!