public WPart(int width, int height, int type, int w_max, FractalArea fa, double dx, double dy, ManualResetEvent de) { this.width = width; this.height = height; this.type = type; this.w_max = w_max; this.fa = fa; this.dx = dx; this.dy = dy; w_data = new int[width, height]; doneEvent = de; }
// Create the threads public void Generate() { // Create array of WParts WpArray = new WPart[NO_OF_THREADS]; // Create array of ManualResetEvents ManualResetEvent[] doneEvents = new ManualResetEvent[NO_OF_THREADS]; double x_step = (FC.fractalArea.x2 - FC.fractalArea.x1) / NO_OF_THREADS; for (int i = 0; i < NO_OF_THREADS; i++) { doneEvents[i] = new ManualResetEvent(false); FractalArea fa_temp = new FractalArea { x1 = FC.fractalArea.x1 + x_step * i, x2 = FC.fractalArea.x1 + x_step * i + x_step, y1 = FC.fractalArea.y1, y2 = FC.fractalArea.y2 }; WPart WP = new WPart(FC.width / NO_OF_THREADS, FC.height, FC.fractalType, FC.w_max, fa_temp, FC.dx, FC.dy, doneEvents[i]); WpArray[i] = WP; ThreadPool.QueueUserWorkItem(WP.ThreadPoolCallback, i); } Calculating = true; // Wait for all threads in pool to complete foreach (var e in doneEvents) { e.WaitOne(); } Calculating = false; Application.DoEvents(); Draw(); PB.Image = DrawArea; }
public void setDefaultArea() { fractalArea = Fractals.getDefaultArea(fractalType); }