using SqlSugar; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using WCS.Data; using WCS.Data.Models; namespace ConsoleApp1 { public class Program { //static CancellationTokenSource _cancelSource = new CancellationTokenSource(); static void Main(string[] args) { SugarBase.DBConnectionString = "Data Source=192.168.249.101;Initial Catalog=YONGGUAN_WCS;Persist Security Info=True;User ID=sa;Pwd=Password@123$%^"; try { int count = SugarBase.DB.Queryable().Count(v => v.TASK_WKSTATUS > 1 && v.TASK_POSIDTO.Contains("Pvc_18")); if (SugarBase.DB.Queryable().Any(v => !SqlFunc.IsNullOrEmpty(v.TASK_POSIDMOVE))) { } //SugarBase.DB.Queryable().Any(v => v.TASK_BOXBARCODE == "agc"); } catch (Exception ex) { Console.WriteLine(ex.Message); } //Console.WriteLine("------------Interrupt方法执行情况---------------"); //Thread t1 = new Thread(DoWork); //t1.Start(); //Thread.Sleep(1000); //t1.Interrupt(); //t1.Join(); //Console.WriteLine("------------Abort方法执行情况---------------"); //Thread t2 = new Thread(DoWork); //t2.Start(); //Thread.Sleep(1000); //t2.Abort(); List lst = new List { 14, 8, 9, 78 }; var abc = new[] { 78, 8, 9, 14 }; string item7 = "6,5"; var srmTunnelList = item7.Split(','); lst = lst.OrderBy(t => Array.IndexOf(abc, t)).ToList(); var outinfoSet = new List(); outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asdfsa", SrmTunnelNo = 5 }); outinfoSet.Add(new WCS_RGVOutInInfo { RGVOUTIN_CONVNO = "asedfsa", SrmTunnelNo = 6 }); var temp = new List(); srmTunnelList.ToList().ForEach(v => temp.Add(outinfoSet.First(t => t.SrmTunnelNo.ToString() == v))); Console.WriteLine("Begin:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); var result = OutTimeClass.OutTimeSomeParemReturn(WCS_GetInTask, 2000,new GetInTaskReply()); //ThreadHelper.TaskThread(LongTimeFunc, 5000); //bool ret = Process(string.Empty, 10000); //Console.WriteLine("Result={0}", ret); Console.WriteLine("End:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } //private static bool Process(string param, int timeout) //{ // bool ret = false; // var task = new System.Threading.Tasks.TaskFactory().StartNew(() => // { // ret = LongTimeFunc(); // }, _cancelSource.Token).Wait(timeout); // _cancelSource.Cancel(); // return ret; //} private static void LongTimeFunc() { Console.WriteLine("执行方法LongTimeFunc开始:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); System.Threading.Thread.Sleep(200); Console.WriteLine("执行方法LongTimeFunc结束:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); //return true; } private static object WCS_GetInTask(object obj) { GetInTaskReply reply; try { reply = Text(); if (reply == null) throw new Exception(); } catch (Exception) { reply = new GetInTaskReply(); reply.ResMessage = string.Format("WCS_GetInTask:接口报错或接口超时,请求位置[{0}]请求条码[{1}]", 1234, 34567); Console.WriteLine(reply.ResMessage + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); } return reply; } public static GetInTaskReply Text() { GetInTaskReply reply = null ; try { reply = new GetInTaskReply(); Console.WriteLine("开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); Thread.Sleep(200); Console.WriteLine("结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); } catch(ThreadInterruptedException e) { Console.WriteLine("ThreadInterruptedException:"+e.Message); reply = null; } catch (Exception ex) { Console.WriteLine("Exception:" + ex.Message); reply = null; } return reply; } public static void Text2() { try { Console.WriteLine("Text2开始" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); Thread.Sleep(200); Console.WriteLine("Text2结束" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); } catch (ThreadInterruptedException e) { Console.WriteLine("ThreadInterruptedException2:" + e.Message); } catch (Exception ex) { Console.WriteLine("Exception2:" + ex.Message); } } static void DoWork() { for (int i = 0; i < 10; i++) { try { Console.WriteLine("第" + i + "循环。"); Thread.Sleep(500); } catch (ThreadInterruptedException e) { Console.WriteLine("第" + i + "循环中,线程被中断,下次循环线程将继续运行。"); } catch (ThreadAbortException e) { Console.WriteLine("第" + i + "循环中,线程被终止,线程将不再继续运行"); } } } [StructLayout(LayoutKind.Sequential)] class A { public bool d = false; public short a = 0; public int b = 0; public long c = 0; } } public class WCS_RGVOutInInfo { /// /// RGV对接口输送线编号 /// public string RGVOUTIN_CONVNO { get; set; } /// /// RGV编号 /// public string RGVOUTIN_RGVNO { get; set; } /// /// 所在plc名称 /// public string PLCNAME { get; set; } /// /// 堆垛机巷道编号 /// public int SrmTunnelNo { get; set; } } class Account { private object thisLock = new object(); int balance; Random r = new Random(); public Account(int initial) { balance = initial; } int WithDraw(int amount) { if (balance < 0) { throw new Exception("负的Balance."); } //确保只有一个线程使用资源,一个进入临界状态,使用对象互斥锁,10个启动了的线程不能全部执行该方法 lock (thisLock) { if (balance >= amount) { Console.WriteLine("----------------------------:" + System.Threading.Thread.CurrentThread.Name + "---------------"); Console.WriteLine("调用Withdrawal之前的Balance:" + balance); Console.WriteLine("把Amount输入 Withdrawal :-" + amount); //如果没有加对象互斥锁,则可能10个线程都执行下面的减法,加减法所耗时间片段非常小,可能多个线程同时执行,出现负数。 balance = balance - amount; Console.WriteLine("调用Withdrawal之后的Balance :" + balance); return amount; } else { //最终结果 return 0; } } } public void DoTransactions() { for (int i = 0; i < 100; i++) { //生成balance的被减数amount的随机数 WithDraw(r.Next(1, 100)); } } } public class GetInTaskReply { /// /// 1:成功,0:失败 /// public bool ResType { get; set; } public string ResMessage { get; set; } public string WMSTaskNum { get; set; } /// /// 任务类型(1:入库2:出库3:移库4:移动(搬运) 5:异常 6:托盘异常退回) /// public int TaskType { get; set; } /// /// 仓库名称 /// public string WareHouseName { get; set; } /// /// 入库巷道(集合巷道,由WCS自行判断入到哪一个巷道,最前面的最优先) /// public string TunnelNum { get; set; } /// /// 目标位置(入库该地址为srm.如果是移动任务,该地址为WCS传递的目标位置) /// public string EndPostion { get; set; } public int Priority { get; set; } public string Memo1 { get; set; } public string Memo2 { get; set; } public string Memo3 { get; set; } } }