public static void For(int start, int end, int chunkSize, ForDelegate action) { object oLock = new object(); ProcessDelegate process = delegate() { for (int n = 0; n < end;) { lock (oLock) { n = start; start += chunkSize; } for (int k = 0; k < chunkSize && n < end; k++, n++) { action(n); } } }; int threads = Environment.ProcessorCount; WaitHandle[] handles = new WaitHandle[threads]; for (int i = 0; i < threads; i++) { handles[i] = process.BeginInvoke(ProcessCallback, process).AsyncWaitHandle; } WaitHandle.WaitAll(handles); }
public static void ForEach <T>(IEnumerable <T> enumerable, ForEachDelegate <T> action) { IEnumerator <T> enumerator = enumerable.GetEnumerator(); object oLock = new object(); ProcessDelegate process = delegate() { while (true) { T current; lock (oLock) { if (!enumerator.MoveNext()) { return; } current = enumerator.Current; } action(current); } }; int threads = Environment.ProcessorCount; WaitHandle[] handles = new WaitHandle[threads]; for (int i = 0; i < threads; i++) { handles[i] = process.BeginInvoke(ProcessCallback, process).AsyncWaitHandle; } WaitHandle.WaitAll(handles); }
public void Start() { ProcessDelegate proc = new ProcessDelegate(DoStart); m_processInfo = new Syscalls.PROCESS_INFORMATION(); CreateProcess(null, CommandLine, InheritHandles, CreationFlags, ref m_startupInfo, out m_processInfo); m_running = true; proc.BeginInvoke(null, null); }
/// <summary> /// 处理队列中的正式数据 /// </summary> /// <param name="state"></param> public void AcceptDataWork(object state) { while (true) { try { AcceptDataEvent.WaitOne(1); while (AcceptDataQue.Count > 0) { ProcessRecord msg = null; lock (AcceptDataQueLock) { if (AcceptDataQue.Count > 0) { msg = AcceptDataQue.Dequeue(); } } if (msg != null) { var channel = EngineContext.Current.Resolve <IChannel>(msg.CHANNEL_TYPE.ToString()); if (null != channel) { ///////////////////////补抓图片////////////////////////////////// if (string.IsNullOrEmpty(msg.PicFullName)) { var channelList = CommHelper.GetOrgInfos(msg.CHN_CODE); var cameraDevice = channelList.Where(x => x.productLine == enumProductLine.IdentificationCamera && x.autoRecognition).FirstOrDefault(); if (null != cameraDevice) { var cameraSDK = EngineContext.Current.Resolve <ICamera>(cameraDevice.deviceType.ToString()); if (null != cameraSDK) { string strPicName = string.Empty; cameraSDK.CapturePicture(cameraDevice.IP, out strPicName); msg.PicFullName = strPicName; } } } ///////////////////////开始流程////////////////////////////////// ProcessDelegate dl = new ProcessDelegate(RunProcess); dl.BeginInvoke(channel, msg, null, null); if (null != OnPlate) { OnPlate(msg); } } } } AcceptDataEvent.Reset(); } catch (Exception ex) { AcceptDataEvent.Reset(); LogHelper.Log.Error(ex.Message, ex.InnerException); } } }
public IAsyncResult BeginProcess(MethodBase method, string operationName, object [] parameters, AsyncCallback callback, object asyncState) { if (context != null) { throw new InvalidOperationException("another operation is in progress"); } context = OperationContext.Current; return(_processDelegate.BeginInvoke(method, operationName, parameters, callback, asyncState)); }
public IAsyncResult BeginProcess(MethodBase method, string operationName, object [] parameters, AsyncCallback callback, object asyncState) { var p = parameters; var retval = _processDelegate.BeginInvoke(method, operationName, true, ref p, OperationContext.Current, callback, asyncState); if (p != parameters) { throw new InvalidOperationException(); } return(retval); }
//start all steps private void btnStart_Click(object sender, EventArgs e) { this.InitDgvRows(); this.timGifAnimation.Enabled = true; this._CurrentStep = 0; ProcessDelegate pdSteps = new ProcessDelegate(Process); pdSteps.BeginInvoke(null, null); }
public IAsyncResult BeginProcess(MethodBase method, string operationName, object [] parameters, AsyncCallback callback, object asyncState) { return(_processDelegate.BeginInvoke(method, operationName, parameters, OperationContext.Current, callback, asyncState)); }
/// <summary> /// Started den asynchronen Vorgang. /// </summary> /// <param name="user">Benutzerdefinierter Wert, der an den Vorgang übergeben wird.</param> public void Start(object user) { ProcessDelegate process = new ProcessDelegate(ProcessWorker); process.BeginInvoke(user, new AsyncCallback(ProcessCallback), process); }
private void ProcessAsync(Simulation.Matrix_Worksheet matrixWS) { ProcessDelegate process = new ProcessDelegate(Process); process.BeginInvoke(matrixWS,null,null); }