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

C#

 
Questiontext editor in c#... Pin
mr.mohsen19-Feb-09 19:33
mr.mohsen19-Feb-09 19:33 
AnswerRe: text editor in c#... Pin
V.19-Feb-09 20:27
professionalV.19-Feb-09 20:27 
AnswerRe: text editor in c#... Pin
Simon P Stevens19-Feb-09 22:31
Simon P Stevens19-Feb-09 22:31 
QuestionHow to give Error Message for the Button second time Click event in C# Pin
ChandrakanthGaddam19-Feb-09 18:48
ChandrakanthGaddam19-Feb-09 18:48 
AnswerRe: How to give Error Message for the Button second time Click event in C# Pin
dan!sh 19-Feb-09 19:02
professional dan!sh 19-Feb-09 19:02 
AnswerRe: How to give Error Message for the Button second time Click event in C# Pin
ABitSmart19-Feb-09 19:06
ABitSmart19-Feb-09 19:06 
GeneralRe: How to give Error Message for the Button second time Click event in C# Pin
ChandrakanthGaddam19-Feb-09 19:25
ChandrakanthGaddam19-Feb-09 19:25 
GeneralRe: How to give Error Message for the Button second time Click event in C# Pin
dojohansen20-Feb-09 0:14
dojohansen20-Feb-09 0:14 
There is nothing Holy about requirements and when they are nonsensical it might be better for everyone if you suggest an improvement to the relevant stakeholders.

That said, all the information you need to code this is to know if the process is running or not. Since only two states are possible, a bool is fitting:

bool running;

With this new state available, you need to set it true when the process starts, false when it ends, and then in your event handler take different courses of action depending on the state of this flag. It really is that simple.

(A general hint: This approach, asking yourself "what information do I need?" first, very often makes solutions to simple problems appear almost automatically.)


void btnRun_click(object sender, EventArgs e)
{
  if (btnRun.Tag != null)
    MessageBox.Show("Not now you idiot, I'm busy.");
  else 
    ThreadPool.QueueUserWorkItem(new WaitCallback(process));
}


void process(object state)
{
  running = true;
  // Use try-finally so the flag is updated even if an exception occurs.
  try
  {
     ...
  }
  finally
  {
     running = false;
  }
}


(The "object state" parameter is required to conform to the WaitCallback delegate signature - you may of course also use it to actually pass information to the method if convenient.)

Hope this helps,

Dag
GeneralRe: How to give Error Message for the Button second time Click event in C# Pin
dan!sh 20-Feb-09 0:25
professional dan!sh 20-Feb-09 0:25 
QuestionConnection failes Pin
picasso219-Feb-09 18:24
picasso219-Feb-09 18:24 
AnswerRe: Connection failes Pin
ABitSmart19-Feb-09 19:32
ABitSmart19-Feb-09 19:32 
QuestionOn system load my C#.NET Program should run. Pin
sakthi_0919-Feb-09 18:00
sakthi_0919-Feb-09 18:00 
AnswerRe: On system load my C#.NET Program should run. Pin
dan!sh 19-Feb-09 18:31
professional dan!sh 19-Feb-09 18:31 
AnswerRe: On system load my C#.NET Program should run. Pin
ABitSmart19-Feb-09 19:01
ABitSmart19-Feb-09 19:01 
GeneralRe: On system load my C#.NET Program should run. Pin
dan!sh 19-Feb-09 19:04
professional dan!sh 19-Feb-09 19:04 
GeneralRe: On system load my C#.NET Program should run. Pin
ABitSmart19-Feb-09 19:08
ABitSmart19-Feb-09 19:08 
QuestionHelp on System.Type.InvokeMember method.... Pin
NeerajSharp19-Feb-09 17:36
NeerajSharp19-Feb-09 17:36 
AnswerRe: Help on System.Type.InvokeMember method.... Pin
Wendelius19-Feb-09 17:57
mentorWendelius19-Feb-09 17:57 
QuestionHelp showing a form - "Object reference not set to an instance of an object." Pin
samskiter19-Feb-09 17:28
samskiter19-Feb-09 17:28 
AnswerRe: Help showing a form - "Object reference not set to an instance of an object." Pin
Wendelius19-Feb-09 17:52
mentorWendelius19-Feb-09 17:52 
GeneralRe: Help showing a form - "Object reference not set to an instance of an object." Pin
samskiter19-Feb-09 18:00
samskiter19-Feb-09 18:00 
GeneralRe: Help showing a form - "Object reference not set to an instance of an object." Pin
Wendelius19-Feb-09 18:13
mentorWendelius19-Feb-09 18:13 
GeneralRe: Help showing a form - "Object reference not set to an instance of an object." Pin
samskiter19-Feb-09 18:21
samskiter19-Feb-09 18:21 
AnswerRe: Help showing a form - "Object reference not set to an instance of an object." Pin
Luc Pattyn19-Feb-09 17:54
sitebuilderLuc Pattyn19-Feb-09 17:54 
GeneralRe: Help showing a form - "Object reference not set to an instance of an object." Pin
samskiter19-Feb-09 17:55
samskiter19-Feb-09 17:55 

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.