Commit 5e620c53 张东亮

添加未处理异常时导出dump文件

1 个父辈 2b1d9553
......@@ -104,7 +104,6 @@ namespace OnlineStore.DeviceLibrary
else
{
var box = boxInfos.Find(s => param.Label_LZ.hSerial.Equals(s.hSerial) && (s.boxBCount < maxCnt && s.boxTCount < maxCnt));
StringBuilder sb = new StringBuilder();
if (box != null)//相同工单且有空位
{
TurnoverBox turnoverBox = turnoverBoxes.Find(s => s.outLet.Equals(box.outlet));
......@@ -174,7 +173,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
sb.Append($"{BoxA.Name}内工单{boxTmp.hSerial}与待出库工单{param.Label_LZ.hSerial}不符,无法出库");
SetWarnMsg($"{BoxA.Name}内工单{boxTmp.hSerial}与待出库工单{param.Label_LZ.hSerial}不符,无法出库");
}
}
else//无A周转信息
......@@ -215,7 +214,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
sb.Append($"{BoxB.Name}内工单{boxTmp1.hSerial}与待出库工单{param.Label_LZ.hSerial}不符,无法出库");
SetWarnMsg($"{BoxB.Name}内工单{boxTmp1.hSerial}与待出库工单{param.Label_LZ.hSerial}不符,无法出库");
}
}
else//无B周转信息
......@@ -239,11 +238,6 @@ namespace OnlineStore.DeviceLibrary
}
}
}
if (!string.IsNullOrEmpty(sb.ToString()))
{
SetWarnMsg(sb.ToString());
}
}
}
......
......@@ -139,14 +139,15 @@ namespace OnlineStore.DeviceLibrary
AgvNode.status = node.status;
AgvNode.level = node.level;
AgvNode.shelf_id = node.shelf_id;
LogUtil.info($"收到AGV服务端消息:【{node.name}】【{node.status.ToString()}】【{node.ToText()}】");
if (node.status.Equals(NodeStatus.RequestEnter))
{
LogUtil.info($"收到AGV服务端消息:【{node.name}】【{node.status.ToString()}】【{node.ToText()}】");
recvAGVSig = true;
BoxEnterProcess();
}
else if (node.status.Equals(NodeStatus.RequestLeave))
{
LogUtil.info($"收到AGV服务端消息:【{node.name}】【{node.status.ToString()}】【{node.ToText()}】");
recvAGVSig = true;
BoxOutProcess();
}
......
......@@ -12,6 +12,7 @@ using System.Windows.Forms;
using OnlineStore.DeviceLibrary;
using System.Runtime.ExceptionServices;
using System.ComponentModel;
using System.IO;
namespace OnlineStore.XLRStore
{
......@@ -57,8 +58,6 @@ namespace OnlineStore.XLRStore
[HandleProcessCorruptedStateExceptions]
static void Main(string[] Args)
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
......@@ -110,45 +109,128 @@ namespace OnlineStore.XLRStore
}
private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{
// LogUnhandledException("CurrentDomain_FirstChanceException", e);
// LogUnhandledException("CurrentDomain_FirstChanceException", e.Exception.StackTrace);
}
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)
{
LogUnhandledException("Application_ThreadException", e.ToString() + "" + e.Exception.ToString() + " ");
LogUnhandledException("Application_ThreadException", e.ToString() + " | " + e.Exception.ToString() + " ");
}
static void LogUnhandledException(string type, string exceptionobj)
{
//这里可以进一步地写日志
LogUtil.error("【" + type + "】" + exceptionobj);
MiniDump.Write(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +"\\"+ DateTime.Now.ToString("yyyyMMddHHmmss") + "-XLR-error.dmp");
MessageBox.Show(exceptionobj, type);
LogUtil.error("【" + type + "】" + exceptionobj);
}
static void Test()
#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,
};
//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);
string s = "http://192.168.101.11/myproject/rest/api/qisda/device/getSize?robotIndex=2&barcode=L165K001877%3bE20200329+0730%3bBQT001200218504192020032915000%3bR04192020042451762%23%230201X104K100CT%2f15000%2f165K001877%2f20200329%23%23";
string param = "robotIndex=2&barcode=L165K001877";
System.Collections.Specialized.NameValueCollection data = new System.Collections.Specialized.NameValueCollection();
Dictionary<string, object> value = new Dictionary<string, object>();
data.Add("robotIndex", 2.ToString());
data.Add("barcode", "L165K001877%3bE20200329+0730%3bBQT001200218504192020032915000%3bR04192020042451762%23%230201X104K100CT%2f15000%2f165K001877%2f20200329%23%23");
value.Add("robotIndex", 2);
value.Add("barcode", "L165K001877%3bE20200329+0730%3bBQT001200218504192020032915000%3bR04192020042451762%23%230201X104K100CT%2f15000%2f165K001877%2f20200329%23%23");
// string param = JsonHelper.SerializeObject(value);
s = "http://192.168.101.11/myproject/service/store/emptyPosForPutin?cids=line-ac-01%2cline-ac-02%2cline-ac-03%2cline-ac-04%2cline-ac-05%2cline-ac-06%2cline-ac-07%2cline-ac-08%2cline-ac-09%2cline-ac-10%2cline-ac-11%2cline-ac-12%2cline-ac-13%2cline-ac-14%2cline-ac-15%2cline-ac-16%2cline-ac-17%2cline-ac-18&code=%3d7x8%3dL0000000IA0106D25D015%3bE20200106+0730%3bB7H.10524.5C1035042020010604000+%3bR035042020010600208%23%23&rfid=B16";
string result = HttpHelper.Post(s, "");
s = "http://192.168.101.11/myproject/rest/api/qisda/device/getSize?robotIndex=2&barcode=L165K001877%3bE20200329+0730%3bBQT001200218504192020032915000%3bR04192020042451762%23%230201X104K100CT%2f15000%2f165K001877%2f20200329%23%23";
result = HttpHelper.Post(s, "");
return;
[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.Create, 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
}
}
}
}
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!