private void addThreadToolStripMenuItem_Click(object sender, EventArgs e) { string promptValue = threadPrompt.ShowDialog("Description", "Adding a new thread..."); int newID = -1; for (int i = 0; i < gameContext.Threads.Count; i++) { if (gameContext.Threads[i].MID != i) { newID = i; break; } } if (newID < 0) { newID = gameContext.Threads.Count; } thread thread = new thread(); thread.setID((uint)newID); thread.MDescription = promptValue; gameContext.Threads.Add(thread); }
private void findWays(thread th, AState state, string way) { if (state.MNextStates.Length != 0) { for (int i = 0; i < state.MNextStates.Length; i++) { AState nextState = (AState)th.MIDToIState[state.MNextStates[i]]; string newString = way; newString += state.buildText(i); findWays(th, nextState, newString); } } else { if (!File.Exists("way0.txt")) { File.Create("way0.txt"); } StreamWriter sw = new StreamWriter("way0.txt", true, System.Text.Encoding.Default); sw.Write(way); sw.Close(); ways++; } }
static void Main(string[] args) { FixedThreadPool fixedThreadPool = new FixedThreadPool(10); for (int i = 0; i < 6; i++) { thread hh = new thread("h"); fixedThreadPool.Execute(hh, Priority.High); } for (int i = 0; i < 6; i++) { thread nn = new thread("n"); fixedThreadPool.Execute(nn, Priority.Normal); } for (int i = 0; i < 6; i++) { thread hh = new thread("h"); fixedThreadPool.Execute(hh, Priority.High); } for (int i = 0; i < 6; i++) { thread ll = new thread("l"); fixedThreadPool.Execute(ll, Priority.Low); } fixedThreadPool.Stop(); Console.ReadKey(); }
public void addStateToThread(AState inState, int oldParentThread) { thread newThread = gc.getThread(inState.MParentThread); thread oldThread = gc.getThread(oldParentThread); oldThread.deleteState(inState.MID); newThread.addState(inState); }
private void открытьToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { gameContext.Load("gc_" + lang + ".json"); thread currThread = new thread(); currThread.Load(openFileDialog1.FileName); gameContext.addThreads(currThread); loadToStateList(); addOriginToolStripMenuItem.Enabled = true; } }
public void Start(int threadCount) { //already started? if (!p_Abort) { return; } //valid thread count if (threadCount <= 0) { throw new Exception("Invalid thread count " + threadCount); } //spawn the threads p_Abort = false; p_Threads = new thread[threadCount]; p_ThreadCount = threadCount; p_ThreadCurrentIndex = 0; for (int c = 0; c < threadCount; c++) { thread t = new thread() { pump = this, stack = new Stack<msg>(), syncronizeLock = new object() }; t.nativeThread = new Thread(t.main) { Priority = ThreadPriority.Highest, Name = p_Name + " [thread: " + c + "]" }; t.nativeThread.Start(); p_Threads[c] = t; } }
private void button1_Click_2(object sender, EventArgs e) { DateTime dat1, dat2; dat1 = dateTimePicker1.Value; dat2 = dateTimePicker2.Value; //type de traitement setChoix(1); //retrieving all the dates contained in the given period as well as all months initdate(dat1, dat2); initMonth(); //initializing the datagridview resultatMensuel.Columns.Clear(); prepareui(); /* * we are goin to define threads that will handle the rest of operation * so as to make the program run faster */ //we define the number of threads to create by assuming there are more than 100 articles int numThreads = 1; if (listArticles.Count > 100) { numThreads = listArticles.Count / 100; } //initialize the number of processes processus = numThreads; string[] keys = listArticles.Keys.ToArray(); int deb = 0, fin = keys.Length; //we disable the export button until the job is done export.Enabled = false; //we create the different threads Thread executor; Thread[] wait = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { Dictionary <string, string> td = new Dictionary <string, string>(); if (numThreads == 1) { thread th = new thread(listArticles, Months, dates, resultatMensuel, export, getChoix(), numThreads); executor = new Thread(new ThreadStart(th.execution)); wait[i] = executor; executor.Start(); } else { if (i < numThreads - 1) { for (int j = 0; j < 100; j++) { td[keys[deb]] = listArticles[keys[deb]]; deb++; } } else { for (int j = deb; j < listArticles.Count; j++) { td[keys[deb]] = listArticles[keys[deb]]; deb++; } } thread th = new thread(td, Months, dates, resultatMensuel, export, getChoix(), numThreads); executor = new Thread(new ThreadStart(th.execution)); wait[i] = executor; executor.Start(); } } }
static void main() { Thread thread = new thread(Task); thread.Start(); }
/// <summary> /// build thread and process list periodically and fire update event and enqueue results for the socket thread /// </summary> void usageThread() { try { int interval = 3000; uint start = Process.GetTickCount(); Dictionary <uint, thread> old_thread_List;// = Process.GetThreadList(); string exeFile = Process.exefile; //read all processes Dictionary <uint, process> ProcList = Process.getProcessNameList(); DateTime dtCurrent = DateTime.Now; //######### var declarations Dictionary <uint, thread> new_ThreadList; uint duration; long system_total; long user_total, kernel_total; //total process spend in user/kernel long thread_user, thread_kernel; //times the thread spend in user/kernel DWORD dwProc; float user_percent; float kernel_percent; ProcessStatistics.process_usage usage; ProcessStatistics.process_statistics stats = null; string sProcessName = ""; List <thread> processThreadList = new List <thread>(); //extended list List <threadStatistic> processThreadStatsList = new List <threadStatistic>(); //to store thread stats //threadtimes threadTimesTotal; while (!bStopMainThread) { eventEnableCapture.WaitOne(); old_thread_List = Process.GetThreadList(); //build a list of threads with user and kernel times System.Threading.Thread.Sleep(interval); //get a new thread list new_ThreadList = Process.GetThreadList(); //build another list of threads with user and kernel times, to compare duration = Process.GetTickCount() - start; ProcList = Process.getProcessNameList(); //update process list dtCurrent = DateTime.Now; system_total = 0; statisticsTimes.Clear(); //look thru all processes foreach (KeyValuePair <uint, process> p2 in ProcList) { //empty the process's thread list processThreadList = new List <thread>(); processThreadStatsList = new List <threadStatistic>(); user_total = 0; //hold sum of thread user times for a process kernel_total = 0; //hold sum of thread kernel times for a process sProcessName = p2.Value.sName; //SUM over all threads with that ProcID dwProc = p2.Value.dwProcID; foreach (KeyValuePair <uint, thread> kpNew in new_ThreadList) { thread_user = 0; thread_kernel = 0; //if the thread belongs to the process if (kpNew.Value.dwOwnerProcID == dwProc) { //is there an old thread entry we can use to calc? thread threadOld; if (old_thread_List.TryGetValue(kpNew.Value.dwThreadID, out threadOld)) { thread_user = Process.GetThreadTick(kpNew.Value.thread_times.user) - Process.GetThreadTick(old_thread_List[kpNew.Value.dwThreadID].thread_times.user); user_total += thread_user; thread_kernel = Process.GetThreadTick(kpNew.Value.thread_times.kernel) - Process.GetThreadTick(old_thread_List[kpNew.Value.dwThreadID].thread_times.kernel); kernel_total += thread_kernel; } //simple list thread threadsOfProcess = new thread(kpNew.Value.dwOwnerProcID, kpNew.Value.dwThreadID, kpNew.Value.thread_times); processThreadList.Add(threadsOfProcess); //extended list threadStatistic threadStats = new threadStatistic( kpNew.Value.dwOwnerProcID, kpNew.Value.dwThreadID, new threadtimes(thread_user, thread_kernel), duration, dtCurrent.Ticks); processThreadStatsList.Add(threadStats); }//if dwProcID matches } //end of sum for process user_percent = (float)user_total / (float)duration * 100f; kernel_percent = (float)kernel_total / (float)duration * 100f; system_total = user_total + kernel_total; // update the statistics with this process' info usage = new ProcessStatistics.process_usage(kernel_total, user_total); // update process statistics //stats = new ProcessStatistics.process_statistics(p2.Value.dwProcID, p2.Value.sName, usage, dtCurrent.Ticks, duration, processThreadList); stats = new ProcessStatistics.process_statistics(p2.Value.dwProcID, p2.Value.sName, usage, dtCurrent.Ticks, duration, processThreadStatsList); //add or update the proc stats if (exeFile != p2.Value.sName || bIncludeMySelf) { //if (sProcessName == "device.exe") // System.Diagnostics.Debug.WriteLine(stats.ToString()); statisticsTimes[p2.Value.sName] = stats; //lock (lockQueue) //{ //System.Diagnostics.Debug.WriteLine("Queue Adding " + stats.sName); //procStatsQueue.Enqueue(stats); procStatsQueueBytes.Enqueue(stats.ToByte()); //} } start = Process.GetTickCount(); }//foreach process onUpdateHandler(new ProcessStatsEventArgs(statisticsTimes, duration)); procStatsQueueBytes.Enqueue(ByteHelper.endOfTransferBytes); ((AutoResetEvent)eventEnableSend).Set(); //dumpStatistics(statisticsTimes); }//while true } catch (ThreadAbortException ex) { System.Diagnostics.Debug.WriteLine("ThreadAbortException: usageThread(): " + ex.Message); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception: usageThread(): " + ex.Message); } System.Diagnostics.Debug.WriteLine("Thread ENDED"); }
private static void thr_kill(thread tid, long sig) ;