public IJobHandle f_createNew(IJob job) { // The main thread uses AutoResetEvent to signal the // registered wait handle, which executes the callback // method: new AutoResetEvent(???) // + true = signaled -> thread continous run // + false = non-signaled -> thread must wait // EventWaitHandle có ba phương thức chính bạn cần quan tâm: // – Close: giải phóng các tài nguyên được sử dụng bởi WaitHandle. // – Reset: chuyển trạng thái của event thành non-signaled. // – Set: chuyển trạng thái của event thành signaled. // – WaitOne([parameters]): Chặn thread hiện tại cho đến khi trạng thái của event được chuyển sang signaled. IJobHandle jo = new JobHandle(job, this); int id = job.f_getId(); JobHandles.Add(id, jo); return(jo); }
public override Task OnConnected() { Connections.Add(Context.ConnectionId, LkHubConnection.Create(Context.ConnectionId, Context.User.Identity.Name)); SendAssets(); return(base.OnConnected()); }
public void f_runLoop(object state, bool timedOut) { if (!_inited) { _inited = true; f_Init(); return; } JobInfo ti = (JobInfo)state; if (!timedOut) { // Tracer.WriteLine("J{0} executes on thread {1}: SIGNAL -> STOP ...", Id, Thread.CurrentThread.GetHashCode().ToString()); ti.f_stopJob(); return; } // Tracer.WriteLine("J{0} executes on thread {1}:DO SOMETHING ...", Id, Thread.CurrentThread.GetHashCode().ToString()); // Do something ... if (msg.Count > 0) { Message m = msg.Dequeue(null); if (m != null) { switch (m.getAction()) { case MESSAGE_ACTION.ITEM_SEARCH: #region if (true) { oLink[] a = new oLink[] { }; if (m.Input != null) { string key = m.Input as string; a = list.Where(x => x.Link.Contains(key) || x.Title.Contains(key) || x.Tags.Contains(key), false, int.MaxValue); m.Output.Counter = a.Length; } else { a = list.Take(10).ToArray(); m.Output.Counter = list.Count; } m.Type = MESSAGE_TYPE.RESPONSE; m.JobName = this._groupName; m.Output.Ok = true; m.Output.PageSize = 10; m.Output.PageNumber = 1; m.Output.Total = list.Count; m.Output.SetData(a); this.StoreJob.f_responseMessageFromJob(m); } #endregion break; case MESSAGE_ACTION.URL_REQUEST_CACHE: #region if (m.Input != null) { string url = m.Input as string; if (urlData.ContainsKey(url)) { string htm = urlData[url]; m.Type = MESSAGE_TYPE.RESPONSE; m.JobName = this._groupName; m.Output.Ok = true; m.Output.SetData(htm); this.StoreJob.f_responseMessageFromJob(m); } else { UrlService.GetAsync(url, m, UrlService.Func_GetHTML_UTF8_FORMAT_BROWSER, (result) => { if (result.Ok) { string htm = result.Html; if (!urlData.ContainsKey(url)) { urlData.Add(url, htm); } m.Type = MESSAGE_TYPE.RESPONSE; m.JobName = this._groupName; m.Output.Ok = true; m.Output.SetData(htm); this.StoreJob.f_responseMessageFromJob(m); } }); } } #endregion break; } } } }