How to disable multi-threads in C# ??

  • Thread starter Thread starter ?code
  • Start date Start date
?

?code

When I develop an application with VS.NET C#, when I click more than
one time on a button, it seems to execute many threads of the same
function.
How to disable it?
thanks
 
when you click the button, the first line of code should disable the button.

MyButton.Enabled = false;

Then call your code. When you are done with your operation, make sure to
re-enable the button.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Why on earth is C# doing this and who decided on something like that!!??
Just kidding, back from reading your blog... ;o)
 
?code,

It doesn't execute more than one thread unless you explicitly tell it
to. If you have code that creates a new thread, then that code is going to
run very fast, because it will spawn the new thread, and then that new
thread will execute new code parallel to the code running in the UI thread
(well, maybe not exactly, depending on number of processors, etc, etc).

What you need to do is set a flag indicating that you already spawned a
thread, and if that flag is set, do not spawn another thread when the button
is pressed.

Hope this helps.
 
I think threads should be subbed for buffered clicks?

Nicholas Paldino said:
?code,

It doesn't execute more than one thread unless you explicitly tell it
to. If you have code that creates a new thread, then that code is going
to run very fast, because it will spawn the new thread, and then that new
thread will execute new code parallel to the code running in the UI thread
(well, maybe not exactly, depending on number of processors, etc, etc).

What you need to do is set a flag indicating that you already spawned a
thread, and if that flag is set, do not spawn another thread when the
button is pressed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


?code said:
When I develop an application with VS.NET C#, when I click more than
one time on a button, it seems to execute many threads of the same
function.
How to disable it?
thanks
 
Huh?

Dan Bass said:
I think threads should be subbed for buffered clicks?

Nicholas Paldino said:
?code,

It doesn't execute more than one thread unless you explicitly tell it
to. If you have code that creates a new thread, then that code is going
to run very fast, because it will spawn the new thread, and then that new
thread will execute new code parallel to the code running in the UI
thread (well, maybe not exactly, depending on number of processors, etc,
etc).

What you need to do is set a flag indicating that you already spawned
a thread, and if that flag is set, do not spawn another thread when the
button is pressed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


?code said:
When I develop an application with VS.NET C#, when I click more than
one time on a button, it seems to execute many threads of the same
function.
How to disable it?
thanks
 
I'm guessing that what's happening is a button is being clicked multiple
times, and am assuming there's some buffering mechanism in the windows
message handling. Would this not give the appearance of "multiple threads"?



Nicholas Paldino said:
Huh?

Dan Bass said:
I think threads should be subbed for buffered clicks?

Nicholas Paldino said:
?code,

It doesn't execute more than one thread unless you explicitly tell it
to. If you have code that creates a new thread, then that code is going
to run very fast, because it will spawn the new thread, and then that
new thread will execute new code parallel to the code running in the UI
thread (well, maybe not exactly, depending on number of processors, etc,
etc).

What you need to do is set a flag indicating that you already spawned
a thread, and if that flag is set, do not spawn another thread when the
button is pressed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


When I develop an application with VS.NET C#, when I click more than
one time on a button, it seems to execute many threads of the same
function.
How to disable it?
thanks
 
Back
Top