473,569 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Situation

Hi

I have occured a very strange situation.

The scenario is as follows. I have two buttons in the form. First
button is Load button and the second one is Delete button. As the name
suggests when 'Load' button is clicked, some data is loaded on the
screen. When the Delete button is hit, this data is removed and the
user does not have access to it further. Load usually takes time and in
some extreme situations it takes 4-5 seconds to load the complete data.
User is not allowed to have Load and Delete operation being executed
simultaneously. Hence while the Load processing is going on, the Delete
button is disabled. Even though the user clicks on the disabled
(Delete) button, its handler is executed and the data is removed from
the screen.

The code in Load button click event handler looks like this:

void Load_Click()
{
DeleteButton.En abled = false;
....
....
//Do heavy processing here
....
....
DeleteButton.En abled = false;
}
Now consider this scenario. The user pressed Load button. It took 5
seconds to processing. In the first line, the Load button is disabled
and the button is indeed disabled visibly.

Within the 5 second time (i.e. during the Delete button is disabled),
the user clicks on the Delete button.

Now, the windows puts this Delete_Click event in the queue. After the
processing for Load_Click is done, it handles Delete_Click event. At
this time, it finds that the DeleteButton.En abled is true (it was set
to true in the last statement of Load_Click). And hence it happily
executes the Delete_Click event handler and removes all the data from
the screen!!

Can anyone tell, how to resolve this situation? I require that the user
clicks should be ignored when the button is disabled.

Best regards
Amit Dedhia

Dec 30 '05 #1
10 1400
Amit <am********@yah oo.com> wrote:

<snip>
Can anyone tell, how to resolve this situation? I require that the user
clicks should be ignored when the button is disabled.


Sure - don't do your heavy processing within the UI thread. During that
time, the clicks aren't actually being processed, they're just being
queued up. By the time they're processed, the delete button is enabled
again.

You should do the heavy processing in another thread, which calls back
to the UI thread to re-enable the delete button afterwards.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more
details.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #2
Perhaps actually hide the button during processing, rather than just
disabling it...

Dec 30 '05 #3
On 30 Dec 2005 03:06:25 -0800, "Amit" <am********@yah oo.com> wrote:
Hi

I have occured a very strange situation.

The scenario is as follows. I have two buttons in the form. First
button is Load button and the second one is Delete button. As the name
suggests when 'Load' button is clicked, some data is loaded on the
screen. When the Delete button is hit, this data is removed and the
user does not have access to it further. Load usually takes time and in
some extreme situations it takes 4-5 seconds to load the complete data.
User is not allowed to have Load and Delete operation being executed
simultaneously . Hence while the Load processing is going on, the Delete
button is disabled. Even though the user clicks on the disabled
(Delete) button, its handler is executed and the data is removed from
the screen.

The code in Load button click event handler looks like this:

void Load_Click()
{
DeleteButton.En abled = false;
...
...
//Do heavy processing here
...
...
DeleteButton.En abled = false;
}
Now consider this scenario. The user pressed Load button. It took 5
seconds to processing. In the first line, the Load button is disabled
and the button is indeed disabled visibly.

Within the 5 second time (i.e. during the Delete button is disabled),
the user clicks on the Delete button.

Now, the windows puts this Delete_Click event in the queue. After the
processing for Load_Click is done, it handles Delete_Click event. At
this time, it finds that the DeleteButton.En abled is true (it was set
to true in the last statement of Load_Click). And hence it happily
executes the Delete_Click event handler and removes all the data from
the screen!!

Can anyone tell, how to resolve this situation? I require that the user
clicks should be ignored when the button is disabled.

When the button is disabled remove the OnClick event handler, this
should be in a try block. In the finally block re-enable the control
and re-assign the event handler.

One thing to question is why the UI and processing code are
co-mingled. The two types of functionality call out for two distinct
objects.

regards
A.G.

Dec 30 '05 #4
Hi,

"Amit" <am********@yah oo.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...


Can anyone tell, how to resolve this situation? I require that the user
clicks should be ignored when the button is disabled.


Why dont you just use a WaitCursor ? in this way your form cannot receive
any click.

Also, consider a more userfriendly interface, like using a thread to load
the data this will prevent the locking of the UI

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 30 '05 #5
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
Can anyone tell, how to resolve this situation? I require that the user
clicks should be ignored when the button is disabled.
Why dont you just use a WaitCursor ? in this way your form cannot receive
any click.


Yes it can. Try this:

using System;
using System.Windows. Forms;
using System.Drawing;
using System.Threadin g;

public class Test
{
static int count;

[STAThread]
static void Main()
{
Form f = new Form();
f.Size = new Size (200, 200);
f.Location = new Point (100, 100);

Button b = new Button();
b.Size = new Size (190, 190);
b.Location = new Point (0, 10);
b.Text = "Click me";
b.Click += new EventHandler(Cl ickHandler);

f.Controls.Add( b);

Application.Run (f);
}

static void ClickHandler(ob ject sender, EventArgs e)
{
Control c = (Control) sender;
count++;
c.Text = count.ToString( );
Cursor.Current = Cursors.WaitCur sor;
Thread.Sleep (2000);
}
}

Start this up, and then click rapidly times on the button, several
times. You'll see the event getting fired multiple times, even though
most of the clicks are performed when the cursor is a wait cursor.
Also, consider a more userfriendly interface, like using a thread to load
the data this will prevent the locking of the UI


That's the right answer :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #6
Hi,

Start this up, and then click rapidly times on the button, several
times. You'll see the event getting fired multiple times, even though
most of the clicks are performed when the cursor is a wait cursor.


Interesting, I had never tried that

I was about to post it when I though that the above problem will happens no
matter what. if you are quick enough you can send a couple of events to the
queue before the handler is even invoked.
Also, consider a more userfriendly interface, like using a thread to load
the data this will prevent the locking of the UI


That's the right answer :)


More like part of it, still the UI needs to reflect the fact that an action
is being performed in the background at least to disable/enable the controls
accordingly.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 30 '05 #7
Hey Jon,

If you are in UK it should be night already , why aren;t you drinking a
pint?

It's just 2PM here and I have one more hour to leave :(


Dec 30 '05 #8
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
Start this up, and then click rapidly times on the button, several
times. You'll see the event getting fired multiple times, even though
most of the clicks are performed when the cursor is a wait cursor.


Interesting, I had never tried that

I was about to post it when I though that the above problem will happens no
matter what. if you are quick enough you can send a couple of events to the
queue before the handler is even invoked.


Yes, that's true. Possibly the easiest way to solve that problem is to
check whether the "sender" of the event is enabled, and to ignore it if
it's not. I *think* that would work...
Also, consider a more userfriendly interface, like using a thread to load
the data this will prevent the locking of the UI


That's the right answer :)


More like part of it, still the UI needs to reflect the fact that an action
is being performed in the background at least to disable/enable the controls
accordingly.


Oh certainly.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #9
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:
If you are in UK it should be night already , why aren;t you drinking a
pint?
I'm still on Christmas holiday - back to work on Tuesday.
It's just 2PM here and I have one more hour to leave :(


LOL. These days I post more from home than from work anyway - hence my
rather higher number of posts this month than normal. (I don't know
what Nick's excuse is :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 30 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1467
by: Neil | last post by:
I have a strange situation. I have a stored procedure that is hanging upon execution, but only some machines and not others. The db is an Access 2000 MDB using ODBC linked tables and a SQL 7 back end. The sp is executed as a pass-through. The sp is fairly simple: UPDATE CUSTOMER SET LastMergeName = . FROM (CUSTOMER C INNER JOIN...
3
2335
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ---------------------------------------------- //example 1: typedef int t_Array; int main(int argc, char* argv)
25
3705
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of...
1
3029
by: davidw | last post by:
I encountered strange issues. I have code like this sqlReader = SqlHelper.ExecuteReader(connString, System.Data.CommandType.Text,sql); It calls Microsoft.ApplicationBlocks.Data to execute a sql statement. It worked fine, but after I did some modifications to my dll, I got error. The strange thing is the first call to the code runs fine,...
0
1101
by: unknown | last post by:
Hi, I am developing an online book store with shopping cart. My shopping cart is represented as a Xml server control and I am using an XSLT to render it at the client side. I am using an XmlDocument object as session variable to represent my shopping cart. Initially when the session starts, I am using the XmlDocument with root and no...
6
2058
by: Hannibal111111 | last post by:
I am getting a strange situation with a .NET 1.1 web application that we have deployed. I have made an update to a code behind page in 1 file, and then made an update to another code behind page. After that I rebuilt everything. This is all on my dev server. Now I move the 1 code behind page and the updated dll to the live server. But I...
2
4098
by: peter | last post by:
Hi, I have very strange situation but first description ;) I have: 1) project in VB.NET, in this f.e. 1 function: Public Function Login(ByVal UserName As String, ByVal UserPassword As String, Optional ByVal ConnectionParamList As String = Nothing) As String
5
1598
by: Developer.Man4 | last post by:
when i try using HttpContext.Current.Server.MapPath(path) from a desktop application built using c# i get a System.NullReferenceException can anyone tell me why and what to do?? m using VS2003 and i have iis 6 installed thanks for time and for ur fast reply
112
4605
by: Prisoner at War | last post by:
Friends, your opinions and advice, please: I have a very simple JavaScript image-swap which works on my end but when uploaded to my host at http://buildit.sitesell.com/sunnyside.html does not work. To rule out all possible factors, I made up a dummy page for an index.html to upload, along the lines of <html><head><title></title></...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.