void CreateThreads() { for (int n = 1; ; n++) { MapObjectAttachedObject startObject = GetFirstAttachedObjectByAlias(string.Format("thread{0}Start", n)); MapObjectAttachedObject endObject = GetFirstAttachedObjectByAlias(string.Format("thread{0}End", n)); if (startObject == null || endObject == null) { break; } MeshObject meshObject = SceneManager.Instance.CreateMeshObject("Base\\Simple Models\\Box.mesh"); if (meshObject == null) { break; } meshObject.SetMaterialNameForAllSubObjects("Black"); meshObject.CastShadows = true; ThreadItem item = new ThreadItem(); item.startObject = startObject; item.endObject = endObject; item.meshObject = meshObject; item.sceneNode = new SceneNode(); item.sceneNode.Attach(item.meshObject); MapObject.AssociateSceneNodeWithMapObject(item.sceneNode, this); threads.Add(item); } UpdateThreads(); }
private void proc(object state) { ThreadItem <TResult> item = state as ThreadItem <TResult>; item.StartTime = DateTime.Now; while (true) { if (item.IsCanceled) { break; } TEntity entity = Queue.Dequeue(); if (entity == null) { break; } TResult r = Processor(entity); item.Result.Add(r); item.ProcessedCount++; } item.EndTime = DateTime.Now; item.waiter.Set(); }
public List <ThreadItem> Start() { actualThreadCount = ThreadCount; if (actualThreadCount > Queue.Count) { actualThreadCount = Queue.Count; } threadList = new List <ThreadItem>(); for (int i = 0; i < actualThreadCount; i++) { ThreadItem item = new ThreadItem(); item.Index = i; item.waiter = new ManualResetEvent(false); Thread thread = new Thread(proc); thread.IsBackground = true; thread.Name = "处理线程_" + i.ToString(); item.Thread = thread; item.IsCanceled = false; threadList.Add(item); } for (int i = 0; i < actualThreadCount; i++) { threadList[i].Thread.Start(threadList[i]); } WaitHandle.WaitAll(threadList.Select(x => x.waiter).ToArray()); return(threadList.ToList()); }
private void ProcessJobQueue() { if (m_NewJobsAdded) { lock (m_NewJobs) { while (m_NewJobs.Count > 0) { AddJob(m_NewJobs.Dequeue()); } m_NewJobsAdded = false; } } while (m_Jobs.Count > 0 && m_Threads.Count > 0) { var job = m_Jobs.Dequeue(); if (!job.IsAborted) { var thread = m_Threads.Pop(); thread.StartJob(job); // add thread to the linked list of active threads thread.NextActive = m_Active; m_Active = thread; } } }
public void Post(SendOrPostCallback callback, object state) { lock (sync) { ThreadItem item = new ThreadItem(callback, state, null); Items.Enqueue(item); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { var uri = "https://adnmb2.com/api/thread/" + (string)e.Parameter; var result = GetPostContent(uri); _threaditems = JsonConvert.DeserializeObject <ThreadItem>(result); contentListView.ItemsSource = _threaditems.replys; }
public PostViewModel(ThreadItem thread) { Console.Write("postviewmodel load\n"); Thread = thread; AgoraService = new AgoraService(thread); Title = thread.Topic; Posts = new ObservableCollection <PostItem>(); LoadPostCommand = new Command(async() => await ExecuteLoadPostCommand()); SendPostCommand = new Command <String>(async(UserPost) => await ExecuteSubmitPostAsync(UserPost)); }
private void CheckActiveJobs() { ThreadItem thread = m_Active; ThreadItem last = null; while (thread != null) { ThreadItem next = thread.NextActive; T job = thread.Data; if (job.IsAborted) { if (last == null) { m_Active = next; } else { last.NextActive = next; } thread.NextActive = null; thread.Reset(); m_Threads.Push(thread); } else if (thread.Data.IsDataReady) { job.OnFinished(); if (OnJobFinished != null) { OnJobFinished(job); } if (last == null) { m_Active = next; } else { last.NextActive = next; } thread.NextActive = null; thread.Reset(); m_Threads.Push(thread); } else { last = thread; } thread = next; } }
public void Execute() { lock (sync) { var oCount = Items.Count; for (int i = 0; i < oCount; i++) { ThreadItem item = Items.Dequeue(); item.Invoke(); } } }
private void StopServiceWorker(object param) { ThreadItem item = param as ThreadItem; if (workers.Contains(item.Worker)) { workers.Remove(item.Worker); } ServiceController service = item.Service; this.Invoke(new StringInvoker(delegate(string serviceName) { statusBox.Text = String.Format( translator.GetString("StoppingMsg"), serviceName ); }), service.ServiceName); service.Stop(); try { service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 15)); } catch (System.ServiceProcess.TimeoutException) { //MessageBox.Show( // translator.GetString("StopTimeoutMsg"), // translator.GetString("TimeoutTitle"), // MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exc) { ExceptionDialog.ShowException(exc); } if (refreshTimer != null) { DiscoverServices(); } this.Invoke(new MethodInvoker(delegate { statusBox.Text = String.Empty; })); }
public void AddTask(Delegate task, object[] @params) { lock (addlock) { ThreadItem item = new ThreadItem(task, @params); if (IsFull) { _queue.Enqueue(item); } else { StartThread(item); } } }
async Task ExecuteCreateThreadCommand(String threadName) { if (IsBusy) { return; } IsBusy = true; try { var uuid = await AgoraService.CreateThreadAsync(threadName); lastThread = await AgoraService.GetThreadAsync(uuid); } finally { IsBusy = false; } CreateThreadCommand.ChangeCanExecute(); }
public void ShutdownQueue() { for (var thread = m_Active; thread != null; thread = thread.NextActive) { thread.Abort(); } while (m_Threads.Count > 0) { m_Threads.Pop().Abort(); } while (m_Jobs.Count > 0) { m_Jobs.Dequeue().AbortJob(); } m_Jobs = null; m_Active = null; m_Threads = null; }
private void StopService(object sender, System.EventArgs e) { if (serviceView.SelectedIndices.Count > 0) { SelectService(ServiceControllerStatus.ContinuePending); Thread worker = new Thread(new ParameterizedThreadStart(StopServiceWorker)); workers.Add(worker); ThreadItem item = new ThreadItem(); item.Service = services.Values[serviceView.SelectedIndices[0]].Controller; item.Worker = worker; worker.Start(item); serviceView.SelectedItems[0].ImageIndex = 1; serviceView.Focus(); SelectService(ServiceControllerStatus.Stopped); } }
public void Send(SendOrPostCallback callback, object state) { if (ThreadID == Thread.CurrentThread.ManagedThreadId) { callback(state); } else { using (ManualResetEvent waitHandle = new ManualResetEvent(false)) { lock (sync) { ThreadItem oWorker = new ThreadItem(callback, state, waitHandle); Items.Enqueue(oWorker); } waitHandle.WaitOne(); } } }
private void StartThread(ThreadItem task) { _threads.Add(task); BackgroundWorker thread = new BackgroundWorker(); thread.DoWork += delegate { task.Invoke(); }; thread.RunWorkerCompleted += delegate { _threads.Remove(task); CheckQueue(); if (_queue.Count == 0 && _threads.Count == 0 && RaiseCompleteEventIfQueueEmpty) { OnCompleted(); } }; thread.RunWorkerAsync(); }
private System.Drawing.Color GetThreadColor(ThreadItem titem) { if (Settings.Instance.UseColorSuspended && titem.WaitReason == KWaitReason.Suspended) return Settings.Instance.ColorSuspended; else if (Settings.Instance.UseColorGuiThreads && titem.IsGuiThread) return Settings.Instance.ColorGuiThreads; return System.Drawing.SystemColors.Window; }
private System.Drawing.Color GetThreadColor(ThreadItem titem) { if (Properties.Settings.Default.UseColorSuspended && titem.WaitReason == KWaitReason.Suspended) return Properties.Settings.Default.ColorSuspended; else if (Properties.Settings.Default.UseColorGuiThreads && titem.IsGuiThread) return Properties.Settings.Default.ColorGuiThreads; return System.Drawing.SystemColors.Window; }
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { _threaditems.Dispose(); _threaditems = null; }
void CreateThreads() { for( int n = 1; ; n++ ) { MapObjectAttachedObject startObject = GetAttachedObjectByAlias( string.Format( "thread{0}Start", n ) ); MapObjectAttachedObject endObject = GetAttachedObjectByAlias( string.Format( "thread{0}End", n ) ); if( startObject == null || endObject == null ) break; MeshObject meshObject = SceneManager.Instance.CreateMeshObject( "Models\\DefaultBox\\DefaultBox.mesh" ); if( meshObject == null ) break; meshObject.SetMaterialNameForAllSubObjects( "Black" ); meshObject.CastShadows = true; ThreadItem item = new ThreadItem(); item.startObject = startObject; item.endObject = endObject; item.meshObject = meshObject; item.sceneNode = new SceneNode(); item.sceneNode.Attach( item.meshObject ); MapObject.AssociateSceneNodeWithMapObject( item.sceneNode, this ); threads.Add( item ); } UpdateThreads(); }
public static void Add(ThreadItem action) { WorkItems.Add(action); }
private void provider_DictionaryAdded(ThreadItem item) { HighlightedListViewItem litem = new HighlightedListViewItem(_highlightingContext, item.RunId > 0 && _runCount > 0); litem.Name = item.Tid.ToString(); litem.Text = item.Tid.ToString(); litem.SubItems.Add(new ListViewItem.ListViewSubItem(litem, "")); litem.SubItems.Add(new ListViewItem.ListViewSubItem(litem, item.StartAddress)); litem.SubItems.Add(new ListViewItem.ListViewSubItem(litem, item.Priority)); litem.Tag = item; litem.NormalColor = GetThreadColor(item); lock (_needsAdd) _needsAdd.Add(litem); }
private void provider_DictionaryModified(ThreadItem oldItem, ThreadItem newItem) { this.BeginInvoke(new MethodInvoker(() => { lock (listThreads) { ListViewItem litem = listThreads.Items[newItem.Tid.ToString()]; if (litem == null) return; if (!_useCycleTime) { if (newItem.ContextSwitchesDelta == 0) litem.SubItems[1].Text = ""; else litem.SubItems[1].Text = newItem.ContextSwitchesDelta.ToString("N0"); } else { if (newItem.CyclesDelta == 0) litem.SubItems[1].Text = ""; else litem.SubItems[1].Text = newItem.CyclesDelta.ToString("N0"); } litem.SubItems[2].Text = newItem.StartAddress; litem.SubItems[3].Text = newItem.Priority; litem.Tag = newItem; (litem as HighlightedListViewItem).NormalColor = GetThreadColor(newItem); _needsSort = true; } })); }
private void provider_DictionaryRemoved(ThreadItem item) { this.BeginInvoke(new MethodInvoker(() => { lock (listThreads) { if (listThreads.Items.ContainsKey(item.Tid.ToString())) listThreads.Items[item.Tid.ToString()].Remove(); } })); }
public static void RunEvents() { lock (lck)//we do not want more than one thread to be querying the database at a time { ThreadPool.Clean(); //figure out what needs to be run var events_to_run = db.EventsToRun(); var current_message_id = ""; Dictionary<string,string> values=null; //send to consumers foreach (DataRow dr in events_to_run.Rows) { string consumer_id = Convert.ToString(dr["consumer_id"]); string message_id = Convert.ToString(dr["message_id"]); if (current_message_id != message_id) { values = db.getValues(message_id); current_message_id = message_id; } var t = new ThreadItem(); t.tag = consumer_id; //if the current consumer isn't busy, process all the events in this group //if (ThreadPool.GetByTag(consumer_id) == null) //{ t.thread = new Thread(() => TryCallConsumer(consumer_id, message_id, values)); ThreadPool.Items.Add(t); t.thread.Start(); //} //else //{ //if thread for this consumer is busy end; it will be handled later //} } Thread.Sleep(1000);//wait a second before querying the database again } }
public AgoraService(ThreadItem thread) { tr = thread; }