//------------------------------------------------------------------------------------------ // Constructor, Finalize, and Dispose /// <summary> Constructor </summary> /// <param name = "pMaxConcurrency"> Max number of running threads allowed </param> /// <param name = "pMinThreadsInPool"> Min number of threads in the pool </param> /// <param name = "pMaxThreadsInPool"> Max number of threads in the pool </param> /// <param name = "pUserFunction"> Reference to a function to call to perform work </param> /// <exception cref = "Exception"> Unhandled Exception </exception> public IOCPCustomThreadPool(int pMaxConcurrency, int pMinThreadsInPool, int pMaxThreadsInPool, DISPATCHER pUserFunction) { try { maxConcurrency = pMaxConcurrency; minThreadsInPool = pMinThreadsInPool; maxThreadsInPool = pMaxThreadsInPool; userFunction = pUserFunction; numberOfThreadsInPool = 0; numberOfActiveThreadsInPool = 0; numberOfWorkItemsInPool = 0; padlock = new object(); isDisposed = false; // Create an IO Completion Port for Thread Pool use unsafe { handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, null, (uint)maxConcurrency); } if (handle == 0) { throw new Exception("Unable To Create IO Completion Port"); } // Allocate and start the Minimum number of threads specified ThreadStart _tsThread = iocpFunction; for (int _i = 0; _i < minThreadsInPool; ++_i) { Thread _thread = new Thread(_tsThread); _thread.Name = string.Format("IOCP_{0}", _i); Thread.AllocateNamedDataSlot(_thread.Name); _thread.Start(); IncrementNumberOfThreadsInPool(); } } catch (Exception _ex) { throw new Exception(string.Format("IOCPCustomThreadPool, Unhandled Exception: {0}", _ex)); } }
public async Task <IHttpActionResult> addStaff(staffModifyReceiver input) { using (var trans = db.Database.BeginTransaction()) { try { var staff = new STAFF { ID = "1", ID_CARD_NUMBER = input.idCardNumber, INSERT_TIME = DateTime.Now, IS_SUPER = "0", NAME = input.name, PASSWORD = input.password, TEL_NUMBER = input.telNumber, UPDATE_TIME = DateTime.Now, ACCOUNT_ID = input.status == "0" ? "p" : input.status == "1" ? "r" : input.status == "2" ? "d" : "x" }; db.STAFF.Add(staff); db.SaveChanges(); var staffID = db.STAFF.OrderByDescending(s => s.ID).FirstOrDefault().ID; System.Diagnostics.Debug.Write(staffID + "\n"); if (input.status == "0") { var patrol = new PATROL { ID = staffID, PATROL_START = input.startTime, PATROL_STOP = input.endTime }; db.PATROL.Add(patrol); } else if (input.status == "1") { var repairer = new REPAIRER { ID = staffID, }; db.REPAIRER.Add(repairer); } else if (input.status == "2") { var dispatcher = new DISPATCHER { ID = staffID, DISPATCH_START = input.startTime, DISPATCH_STOP = input.endTime }; db.DISPATCHER.Add(dispatcher); } await db.SaveChangesAsync(); trans.Commit(); NotificationController.NotificationCallbackMsg("新增员工" + input.name + " 编号" + staff.ID); return(Ok(new staffAddDto { data = getDtoList(), info1 = "ok", info2 = staff.ACCOUNT_ID })); } catch (Exception e) { trans.Rollback(); System.Diagnostics.Debug.Write(e); return(Ok(returnHelper.fail())); } } }