Reputation: 169
I made a very simple program, but when I close it using the red X at the top right, I can still see it in the Windows Task Manager listed under processes. The program is still running and consuming memory. How can I avoid this?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
namespace PS3Controller
{
public partial class Form1 : Form
{
GamePadState pad;
Vector2 centroIzq = new Vector2(138, 132);
Vector2 centroDer = new Vector2(139, 252);
float distancia = 20f;
float ledIzqAngulo = 0;
float ledDerAngulo = 0;
float ledIzqVelocidad = 0.0022f;
float ledDerVelocidad = 0.0022f;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
pad = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
if (pad.Buttons.Y == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledTtriangulo.Visible = true;
else
ledTtriangulo.Visible = false;
if (pad.Buttons.X == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledCuadrado.Visible = true;
else
ledCuadrado.Visible = false;
if (pad.Buttons.A == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledX.Visible = true;
else
ledX.Visible = false;
if (pad.Buttons.B == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledCirculo.Visible = true;
else
ledCirculo.Visible = false;
if (pad.DPad.Left == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledIzq.Visible = true;
else
ledIzq.Visible = false;
if (pad.DPad.Right == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledDer.Visible = true;
else
ledDer.Visible = false;
if (pad.DPad.Up == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledArriba.Visible = true;
else
ledArriba.Visible = false;
if (pad.DPad.Down == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledAbajo.Visible = true;
else
ledAbajo.Visible = false;
if (pad.Buttons.Start == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledStart.Visible = true;
else
ledStart.Visible = false;
if (pad.Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledSelect.Visible = true;
else
ledSelect.Visible = false;
if (pad.Buttons.LeftShoulder == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledL1.Visible = true;
else
ledL1.Visible = false;
if (pad.Buttons.RightShoulder == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledR1.Visible = true;
else
ledR1.Visible = false;
if (pad.Buttons.BigButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
ledHome.Visible = true;
else
ledHome.Visible = false;
if (pad.Triggers.Left > 0)
ledL2.Visible = true;
else
ledL2.Visible = false;
if (pad.Triggers.Right > 0)
ledR2.Visible = true;
else
ledR2.Visible = false;
lblIzqX.Text = pad.ThumbSticks.Left.X.ToString();
lblIzqY.Text = pad.ThumbSticks.Left.Y.ToString();
lblDerX.Text = pad.ThumbSticks.Right.X.ToString();
lblDerY.Text = pad.ThumbSticks.Right.Y.ToString();
Vector2 ledIzqPos = new Vector2(
(float)Math.Cos(ledIzqAngulo) * distancia,
(float)Math.Sin(ledIzqAngulo) * distancia);
Vector2 ledDerPos = new Vector2(
(float)Math.Cos(ledDerAngulo) * distancia,
(float)Math.Sin(ledDerAngulo) * distancia);
if (pad.ThumbSticks.Right.X == 0 &&
pad.ThumbSticks.Right.Y == 0)
{
ledPadDer.Top = 139;
ledPadDer.Left = 252;
}
if (pad.ThumbSticks.Left.X == 0 &&
pad.ThumbSticks.Left.Y == 0)
{
ledPadIzq.Top = 138;
ledPadIzq.Left = 132;
}
}
}
}
Upvotes: 0
Views: 1219
Reputation: 995
Are you sure its your app that is still running or is it YourApp.vshost.exe? The vshost is for Visual Studio and will always run while you have your project open.
Upvotes: 3
Reputation: 16310
Be sure to close all the thread of that process...Sometime, the thread keep process to keep executing though the form is closed...You can do this in OnClosing
method of windows form......
Upvotes: 4