Click here to Skip to main content
15,900,378 members
Home / Discussions / C#
   

C#

 
QuestionHow can I run an executable from within my C# app Pin
sas94913-Aug-06 5:32
sas94913-Aug-06 5:32 
AnswerRe: How can I run an executable from within my C# app Pin
Not Active3-Aug-06 5:42
mentorNot Active3-Aug-06 5:42 
AnswerUse Rar Pin
Ennis Ray Lynch, Jr.3-Aug-06 5:45
Ennis Ray Lynch, Jr.3-Aug-06 5:45 
AnswerRe: How can I run an executable from within my C# app Pin
Dustin Metzgar3-Aug-06 5:54
Dustin Metzgar3-Aug-06 5:54 
QuestionXML Question [modified] Pin
SoftcodeSoftware3-Aug-06 5:18
SoftcodeSoftware3-Aug-06 5:18 
AnswerRe: XML Question Pin
Stefan Troschuetz3-Aug-06 5:28
Stefan Troschuetz3-Aug-06 5:28 
AnswerRe: XML Question Pin
SoftcodeSoftware3-Aug-06 5:38
SoftcodeSoftware3-Aug-06 5:38 
Questioninterupting the loop with the button [modified] Pin
Blubbo3-Aug-06 5:00
Blubbo3-Aug-06 5:00 
I have a code that monitors the electrical loop. Once the button is pressed, it would loop until the button is pressed. The problem is that when the code loops (I use while loop), the button cannot be pressed and the programs acts like as if it is locked up. How do I get the program check for any event while looping? Like for example, in borland c++, it uses "Application->ProcessMessages()".

How do I apply this to Visual Studio.NET?

Unsure | :~


-- modified at 11:16 Thursday 3rd August, 2006

Code sample below:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace loop_test
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.NumericUpDown numUpDn;
private System.Windows.Forms.Button btnLoop;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
this.btnLoop.BackColor = System.Drawing.Color.Red;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLoop = new System.Windows.Forms.Button();
this.numUpDn = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.numUpDn)).BeginInit();
this.SuspendLayout();
//
// btnLoop
//
this.btnLoop.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnLoop.Location = new System.Drawing.Point(56, 16);
this.btnLoop.Name = "btnLoop";
this.btnLoop.Size = new System.Drawing.Size(176, 96);
this.btnLoop.TabIndex = 0;
this.btnLoop.Text = "Loop Stopped";
this.btnLoop.Click += new System.EventHandler(this.btnLoop_Click);
this.btnLoop.BackColorChanged += new System.EventHandler(this.btnLoop_BackColorChanged);
//
// numUpDn
//
this.numUpDn.Location = new System.Drawing.Point(72, 136);
this.numUpDn.Name = "numUpDn";
this.numUpDn.TabIndex = 3;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 174);
this.Controls.Add(this.numUpDn);
this.Controls.Add(this.btnLoop);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Loop interruption Test";
((System.ComponentModel.ISupportInitialize)(this.numUpDn)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btnLoop_Click(object sender, System.EventArgs e)
{
if (this.btnLoop.BackColor == System.Drawing.Color.Red)
this.btnLoop.BackColor = System.Drawing.Color.Lime;
else
this.btnLoop.BackColor = System.Drawing.Color.Red;

}

private void btnLoop_BackColorChanged(object sender, System.EventArgs e)
{
while (this.btnLoop.BackColor == System.Drawing.Color.Lime)
{
this.numUpDn.Value += 1;
this.numUpDn.Update();
Thread.Sleep(500);
}
}
}
}
AnswerRe: interupting the loop with the button Pin
User 66583-Aug-06 5:09
User 66583-Aug-06 5:09 
AnswerRe: interupting the loop with the button Pin
Not Active3-Aug-06 5:14
mentorNot Active3-Aug-06 5:14 
AnswerRe: interupting the loop with the button Pin
Stefan Troschuetz3-Aug-06 5:21
Stefan Troschuetz3-Aug-06 5:21 
GeneralRe: interupting the loop with the button Pin
Blubbo3-Aug-06 5:26
Blubbo3-Aug-06 5:26 
AnswerRe: interupting the loop with the button Pin
Nader Elshehabi3-Aug-06 5:31
Nader Elshehabi3-Aug-06 5:31 
QuestionAsynchronous socket question Pin
Madmaximus3-Aug-06 4:39
Madmaximus3-Aug-06 4:39 
AnswerRe: Asynchronous socket question Pin
Tim Kohler3-Aug-06 5:56
Tim Kohler3-Aug-06 5:56 
GeneralPrefix Pin
Ennis Ray Lynch, Jr.3-Aug-06 5:59
Ennis Ray Lynch, Jr.3-Aug-06 5:59 
AnswerRe: Asynchronous socket question Pin
RizwanSharp3-Aug-06 6:11
RizwanSharp3-Aug-06 6:11 
QuestionImpersonation + Process.Start Pin
Gonzalo Brusella3-Aug-06 4:12
Gonzalo Brusella3-Aug-06 4:12 
AnswerRe: Impersonation + Process.Start Pin
Judah Gabriel Himango3-Aug-06 6:25
sponsorJudah Gabriel Himango3-Aug-06 6:25 
GeneralRe: Impersonation + Process.Start Pin
Judah Gabriel Himango3-Aug-06 6:37
sponsorJudah Gabriel Himango3-Aug-06 6:37 
GeneralRe: Impersonation + Process.Start Pin
Gonzalo Brusella3-Aug-06 7:05
Gonzalo Brusella3-Aug-06 7:05 
QuestionCombobox problem Pin
ZeinaBaG3-Aug-06 3:37
ZeinaBaG3-Aug-06 3:37 
AnswerRe: Combobox problem Pin
stancrm3-Aug-06 3:44
stancrm3-Aug-06 3:44 
Questionspeed up application Pin
V.3-Aug-06 3:19
professionalV.3-Aug-06 3:19 
AnswerRe: speed up application Pin
yueue3-Aug-06 3:27
yueue3-Aug-06 3:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.