private void Form1_Shown(object sender, EventArgs e) { bm = new Bitmap(Width, Height); //param.file = "test1"; param.file = "cunami2"; param.gx = -0.01; param.reinit = true; reinitcallback = new MyCallbackDelegate(ReInit); formparam = new FormParam(); formparam.Show(); formparam.InitParam("Demos", reinitcallback); //formparam.Left = 500; gform = Graphics.FromHwnd(this.Handle); g = Graphics.FromImage(bm); // instrument.zoom = true; // instrument.zoomx = formparam.sc instrument.zoomx; timer1.Enabled = false; ReceiveWorkerThread.WorkerReportsProgress = true; ReceiveWorkerThread.RunWorkerAsync(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { run = false; ReceiveWorkerThread.Dispose(); }
private void ReceiveWorkerThread_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; ; i++) { if (!run) { Thread.Sleep(15); continue; } /* * if (!run) * { * //Thread.CurrentThread.Abort(); * return; * } */ if (needinit && param.reinit) { // scene.init("Demos\\cunami"); scene.SetInstrument(instrument); scene.init("Demos\\" + param.file); needclear = true; } if (needinit) { needinit = false; } if (instrument.changeinstrument) { instrument.changeinstrument = false; scene.SetInstrument(instrument); } if (instrument.step) { instrument.step = false; scene.RunPhysicStep(true); ThreadParam p = new ThreadParam(); p.world = scene.GetScene(); // p.timers = TimeUtil.Instance().GetTimers(); ReceiveWorkerThread.ReportProgress(0, p); } if (instrument.save) { instrument.save = false; instrument.none = true; instrument.changeinstrument = false; } if (instrument.mouseDown) { // scene.ClosePipe(); if (instrument.drop) { //scene.AddFluidToPoint(instrument.mousex,instrument.mousey,10); } } if (!stopped) { scene.RunPhysicStep(false); } if (ReceiveWorkerThread.CancellationPending == true) { break; } if (i % 10 == 0 && !stopped) { //isdraw = true; // World world2 = scene.GetScene(); // timers ThreadParam p = new ThreadParam(); p.world = scene.GetScene(); // p.timers = TimeUtil.Instance().GetTimers(); ReceiveWorkerThread.ReportProgress(0, p); //while (isdraw) ; Thread.Sleep(125); } // if (i % 3 == 0 && !stopped) // Thread.Sleep(4); //if (i % 7 == 0) // Thread.Sleep(362); } }