private void beginRenderObjectPool(object startData) { ThreadStartData tsd = (ThreadStartData)startData; int f = 0; foreach (IScannable obj in _objectPool) { BoundingRectangle br = obj.BoundingBox; if (obj.BoundingBox.Intersects(new BoundingRectangle(tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY))) { IScannable newObj = (IScannable)obj.Clone(); IList <PixelSpan> spans = null; if (br.Width >= br.Height) { spans = _spanGenerator.GetHorizontalSpans(newObj, tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY, _fillPool[f]); } else { spans = _spanGenerator.GetVerticalSpans(newObj, tsd.MinX, tsd.MinY, tsd.MaxX, tsd.MaxY, _fillPool[f]); } foreach (PixelSpan ps in spans) { _rasterData.BlendSpan(ps); } } f++; } }
public static void Main() { // Create a new Thread object specifying DisplayMessage // as the method it will execute. Thread thread = new Thread(DisplayMessage); // make this a foreground thread - this is the // default - call used for example purposes thread.IsBackground = false; // Create a new ThreadStartData object to configure the thread. ThreadStartData config = new ThreadStartData(5, "A thread example.", 500); TraceMsg("Starting new thread."); // Start the new thread and pass the ThreadStartData object // containing the initialization data. thread.Start(config); // Continue with other processing. for (int count = 0; count < 13; count++) { TraceMsg("Main thread continuing processing..."); Thread.Sleep(200); } // Wait to continue. Console.WriteLine(Environment.NewLine); Console.WriteLine("Main method complete. Press Enter."); Console.ReadLine(); }
private void generateMaze(int resolution) { panel1.Visible = false; panel1.Controls.Clear(); currentBlock = null; _exitBlock = null; _currentResolution = resolution; _width = panel1.Width / resolution; _height = panel1.Height / resolution; _maze = null; updateData("Initialising thread...", -1); Thread.Sleep(100); var tsd = new ThreadStartData { height = _height, resolution = resolution, width = _width, useMax = Settings.Default.PrimsRandomUseMax, randommaximum = (int)Settings.Default.PrimsRandomMaximum, revealMaze = Settings.Default.RevealMaze }; _regenerationThread = new Thread(regenerationThread_DoWork) { Priority = ThreadPriority.Lowest }; _regenerationThread.Start(tsd); }
// Declare the method that will be executed in its own thread. The // method displays a message to the console a specified number of // times, sleeping between each message for a specified duration. private static void DisplayMessage(object config) { ThreadStartData data = config as ThreadStartData; if (data != null) { for (int count = 0; count < data.Iterations; count++) { TraceMsg(data.Message); // Sleep for the specified period. Thread.Sleep(data.Delay); } } else { TraceMsg("Invalid thread configuration."); } }
private void generateMaze(int resolution) { panel1.Visible = false; panel1.Controls.Clear(); updateData("Initialising thread...", -1); Thread.Sleep(100); var tsd = new ThreadStartData { height = panel1.Width / resolution, width = panel1.Height / resolution, }; _regenerationThread = new Thread(regenerationThread_DoWork) { Priority = ThreadPriority.Lowest }; _regenerationThread.Start(tsd); }
private static Polygon mergePartialBuffers(List <Polygon> buffers, bool allowParallels) { if (!allowParallels || buffers.Count < 20) { return(mergePartialBuffers(buffers)); } else { Thread t = new Thread(mergePartialBuffers); List <Polygon> buffersForAnotherThread = new List <Polygon>(); List <Polygon> buffersForThisThread = new List <Polygon>(); for (int i = 0; i < buffers.Count; i++) { if (i > buffers.Count / 2) { buffersForAnotherThread.Add(buffers[i]); } else { buffersForThisThread.Add(buffers[i]); } } ThreadStartData tsd = new ThreadStartData(); tsd.Buffers = buffersForAnotherThread; t.Start(tsd); Polygon p = mergePartialBuffers(buffersForThisThread); t.Join(); ICollection <IGeometry> gc = p.Union(tsd.Result); if (gc.Count > 0) { return((Polygon)((GeometryCollection)gc)[0]); } else { return(null); } } }
private static Polygon mergePartialBuffers(List<Polygon> buffers, bool allowParallels) { if (!allowParallels || buffers.Count < 20) return mergePartialBuffers(buffers); else { Thread t = new Thread(mergePartialBuffers); List<Polygon> buffersForAnotherThread = new List<Polygon>(); List<Polygon> buffersForThisThread = new List<Polygon>(); for (int i = 0; i < buffers.Count; i++) { if(i > buffers.Count / 2) buffersForAnotherThread.Add(buffers[i]); else buffersForThisThread.Add(buffers[i]); } ThreadStartData tsd = new ThreadStartData(); tsd.Buffers = buffersForAnotherThread; t.Start(tsd); Polygon p = mergePartialBuffers(buffersForThisThread); t.Join(); ICollection<IGeometry> gc = p.Union(tsd.Result); if (gc.Count > 0) return (Polygon)((GeometryCollection)gc)[0]; else return null; } }
private void generateMaze(int resolution) { panel1.Visible = false; panel1.Controls.Clear(); updateData("Initialising thread...", -1); Thread.Sleep(100); var tsd = new ThreadStartData { height = panel1.Width / resolution, width = panel1.Height / resolution, }; _regenerationThread = new Thread(regenerationThread_DoWork) {Priority = ThreadPriority.Lowest}; _regenerationThread.Start(tsd); }