private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Остановливаем обмен _timer.Stop(); // Закрываем порт if (_port != null && _port.IsOpen) { _port.Close(); } // Сохраняем информацию о сдвигах SaveShiftFields(); }
private void btnAnimStop_Click(object sender, EventArgs e) { tm.Stop(); btnAnimStart.Enabled = true; btnAnimStop.Enabled = false; btnAnimNext.Enabled = !changed; }
/// <summary> /// Stops the video capture /// </summary> public void Stop() { try { // stop the timer m_stopped = true; //this.m_captureTimer.Stop(); m_timer.Stop(); // disconnect from the video source Application.DoEvents(); WebCamAPI.SendMessage(m_captureHandlerWindow, WebCamAPI.WM_CAP_DISCONNECT, 0, 0); } catch (Exception ex) { string errorMsg = "Failed in Stop(). Error: " + ex.Message; System.Diagnostics.Debug.WriteLine(errorMsg); } }
/* Stops the image provider and handles exceptions. */ private void Stop() { if (my_trigger != null) { if (my_trigger.IsRunning) { my_trigger.Stop(); OnGrabbingStoppedEventCallback(); } } /* Stop the grabbing. */ try { m_imageProvider.Stop(); } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
//public Udp(IPAddress _addrTo, int _portTo, IPAddress _addrFrom, int _portFrom) public Udp(IPAddress _addrTo, int _portTo) { addrTo = _addrTo; //addrFrom = _addrFrom; portTo = _portTo; //portFrom = _portFrom; endPointTo = new IPEndPoint(addrTo, portTo); //endPointFrom = new IPEndPoint(addrFrom, portFrom); endPointFrom = new IPEndPoint(IPAddress.Any, portTo); try { udpClient.Bind(endPointFrom); } catch (SocketException ex) { throw ex; } com_timer = new Multimedia.Timer(); com_timer.Stop(); com_timer.Tick += com_timer_Tick; com_timer.Period = 1; com_timer.Resolution = 0; }
bool Disconnect() { try { if (videoDevice != null && videoDevice.IsRunning) { videoDevice.SignalToStop(); //videoDevice.Stop(); //videoDevice.NewFrame -= videoDevice_NewFrame; frmMain.videoSourcePlayer.NewFrame -= videoSourcePlayer_NewFrame; tmr.Stop(); videoDevice = null; } } catch { return(false); } return(true); }
public void stop() { timer.Stop(); }
private void CreateRandomObjects() { #if WINFORMS tmr.Stop(); #endif Thread.Sleep(15); // Give the SimLoop enough time to finish bodies.Clear(); forces.Clear(); switch (mode) { case Modes.Standard: Random rnd = new Random(); int n = rnd.Next(3, (int)Math.Sqrt(bounds.Width)); double mass; double x; double y; for (int i = 0; i < n; i++) { while (true) { bool isValid = true; mass = rnd.NextDouble() * 100 + 20; x = rnd.NextDouble() * bounds.Width - bounds.Width / 2; y = rnd.NextDouble() * bounds.Height - bounds.Height / 2; RectangleF r = new RectangleF((float)(x - mass / 2) - 5, (float)(y - mass / 2) - 5, (float)mass + 10, (float)mass + 10); if (x - mass / 2 < bounds.X || y - mass / 2 < bounds.Y || x + mass > bounds.Width / 2 || y + mass > bounds.Height) { isValid = false; } else { for (int j = 0; j < bodies.Count; j++) { double m = bodies[j].Mass; RectangleF rp = new RectangleF((float)(bodies[j].X1 - m / 2), (float)(bodies[j].Y1 - m / 2), (float)m, (float)m); rp.Inflate(5, 5); #if WINFORMS if (rp.IntersectsWith(r)) { #else if (rp.Intersects(r)) { #endif isValid = false; break; } } } if (isValid) { break; } } bodies.Add(new Body2D(mass, x, y) { Color = Color.FromArgb((int)(rnd.NextDouble() * 255), (int)(rnd.NextDouble() * 255), (int)(rnd.NextDouble() * 255)) }); } forces.Add(gravity); forces.Add(wind); break; case Modes.Planetarium: #if WINFORMS bodies.Add(new Body2D(200, 0, 0) { Color = Color.Yellow, Movable = false }); bodies.Add(new Body2D(30, 700, 0) { Color = Color.DeepSkyBlue, HistorySize = 1000 }); bodies[1].Velocity = new Vector(200, 90 * Constants.ToRad, bodies[1].Origin); bodies.Add(new Body2D(20, 0, -500) { Color = Color.OrangeRed, HistorySize = 1000 }); bodies[2].Velocity = new Vector(200, 0 * Constants.ToRad, bodies[2].Origin); bodies.Add(new Body2D(40, -500, 0) { Color = Color.YellowGreen, HistorySize = 1000 }); bodies[3].Velocity = new Vector(220, 290 * Constants.ToRad, bodies[3].Origin); #else bodies.Add(new Body2D(200, 0, 0) { Color = Colors.Yellow, Movable = false }); bodies.Add(new Body2D(30, 700, 0) { Color = Colors.DeepSkyBlue, HistorySize = 1000 }); bodies[1].Velocity = new Vector(200, 90 * Constants.ToRad, bodies[1].Origin); bodies.Add(new Body2D(20, 0, -500) { Color = Colors.OrangeRed, HistorySize = 1000 }); bodies[2].Velocity = new Vector(200, 0 * Constants.ToRad, bodies[2].Origin); bodies.Add(new Body2D(40, -500, 0) { Color = Colors.YellowGreen, HistorySize = 1000 }); bodies[3].Velocity = new Vector(220, 290 * Constants.ToRad, bodies[3].Origin); #endif break; } #if WINFORMS tmr.Start(); #endif }
private void FrameSender_Leave(object sender, EventArgs e) { fastTimer.Stop(); }
void com_timer_Tick(object sender, EventArgs e) { try { if (!active || !udpClient.Connected) { com_timer.Stop(); rx_queue.Clear(); return; } if (udpClient.Available > 1) { byte[] tmp = new byte[udpClient.Available]; udpClient.Receive(tmp); foreach (byte b in tmp) { rx_queue.Enqueue(b); } } if (state_rx == STATE_RX.ADDR) //считываем адрес { byte[] tmp = new byte[2]; if (rx_queue.Count >= tmp.Length) { for (int i = 0; i < tmp.Length; i++) { tmp[i] = rx_queue.Dequeue(); } command_in.address = (ushort)((tmp[1] << 8) + (tmp[0])); state_rx = STATE_RX.CNT; } } if (state_rx == STATE_RX.CNT) //считываем размер полученных данных { byte[] tmp = new byte[2]; if (rx_queue.Count >= tmp.Length) { for (int i = 0; i < tmp.Length; i++) { tmp[i] = rx_queue.Dequeue(); } command_in.count = (ushort)((tmp[1] << 8) + (tmp[0])); state_rx = STATE_RX.DATA; } } if (state_rx == STATE_RX.DATA) //считываем сами данные { if (rx_queue.Count >= command_in.count) //принимаем данные согласно протоколу в размере command_in.count { command_in.SetDataNewSize(command_in.count); for (int i = 0; i < command_in.count; i++) { command_in.data[i] = rx_queue.Dequeue(); } command_in.result = CommandResult.Success; com_timer.Stop(); rx_queue.Clear(); //вычитываем в никуда данные из буфера если там есть что-то if (udpClient.Available > 0) { byte[] tmp = new byte[udpClient.Available]; udpClient.Receive(tmp); } received(command_in); } else //рукожопный костыль, созданный для приема команды НЕ по протоколу в количестве 14 байт данных (спасибо Захаренко, создавшему эту команду) { command_in.SetDataNewSize((ushort)rx_queue.Count); int tmpCnt = rx_queue.Count; for (int i = 0; i < tmpCnt; i++) { command_in.data[i] = rx_queue.Dequeue(); } command_in.result = CommandResult.Success; com_timer.Stop(); rx_queue.Clear(); //вычитываем в никуда данные из буфера если там есть что-то if (udpClient.Available > 0) { byte[] tmp = new byte[udpClient.Available]; udpClient.Receive(tmp); } received(command_in); } } if (time <= 0) { command_in.result = CommandResult.Timeout; com_timer.Stop(); rx_queue.Clear(); received(command_in); } time -= (uint)com_timer.Period; return; } catch (Exception ex) { throw ex; } }