5 Replies - 6167 Views - Last Post: 26 September 2013 - 07:54 AM

#1 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,641
  • Joined: 24-September 10

WinForms app, gui thread blocked, clicking around causes error.

Posted 10 July 2013 - 02:17 PM

Excuse the topic title, I couldn't think of a good way to word it in a short title form.

So let me describe my situation.

I have a WinForms application that connects to a server via WCF.

Communication with the server is very common and can occur frequently when typing or pressing buttons.

For all intents and purposes it works excactly as I expect, and works very well. This product has been deployed for a few years now.

Thing is when dealing with connection issues, for instance if communication with the server times out.

I have the client communication policy set to timeout after 10 seconds of not receiving a response. Most communication occurs directly on the gui thread, and the gui just blocks while waiting for responses. This is no problem as a response tends to come back in under a second, and anyways, I want it to act this way.

Problem is if a bad timeout occurs, that's 10+ seconds (a few extra seconds sometimes creep in because of whatever reason... random bits of code or the local network resolving itself... tacking a few extra seconds on the end). In this period of 10+ seconds most users get impatient and start clicking around a bit.

While I'm debugging this the thread just blocks the entire time and basically ignores these clicks.

When deployed though, for the first 3 or 4 seconds everything seems to block just fine. But it appears as if after 4 seconds of clicking around while it's blocking in this scenario, .Net bugs out, and pops up a Windows error box saying that the application is non-responsive and does the user want to wait for the app to become responsive or to shut it down.

This message often goes a way after the 10+ seconds of timeout time and the app does become responsive... though it tends to tack another 10 or so seconds of wait time. This is 20 seconds (15 seconds with the message in front of the user) where impatient layman user is going "GRRRR UGH!".

What I suspect is the issue is that since the gui thread of my app is blocking while this timeout wait is occurring, Windows determines that this means 'unresponsive' app because the gui thread doesn't do anything for a few seconds. And I'm guessing that threshold is about 4, maybe 5 seconds. So if the user clicks a bunch of times after that, Windows thinks the program has haulted for whatever reason and displays this message.



What I want, and what this thread is started for, is maybe some suggestions on how to more elegantly deal with this situation.

Is This A Good Question/Topic? 0
  • +

Replies To: WinForms app, gui thread blocked, clicking around causes error.

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9574
  • View blog
  • Posts: 36,266
  • Joined: 12-June 08

Re: WinForms app, gui thread blocked, clicking around causes error.

Posted 10 July 2013 - 02:27 PM

Well.. you can do a few things. First dump some of that potentially blocking/time out code in a task (or a thread)... and while it is away disable the form, change the cursor to the 'waiting' cursor, and maybe throw up a modal dialog of an animation of a progress bar chugging with the message "totes brb! kthnxbi!" in a label above the progress bar as it ticks by.

Second - you can just disable the form until it comes back. Sure, a bit annoying, but maybe throw up a message in the title bar saying "loading" or what ever...

Those are the two main things that come to mind..

Stupid users clicking everywhere!
Was This Post Helpful? 0
  • +
  • -

#3 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,641
  • Joined: 24-September 10

Re: WinForms app, gui thread blocked, clicking around causes error.

Posted 10 July 2013 - 02:34 PM

YEah I was thinking those as well.

My qualm is that I communicate so frequently, this is basically going to happen every single time I communicate to the server. I can't anticipate that it's going to timeout (if I could I just wouldn't communicate in the first place). I'll have to just block the form during that time.

An issue I have is that the design of the system is around an object that uncovers the methods that I can call on the server (simple things like retrieve, commit, call, etc). This object doesn't know about the gui directly... this means EVERY time I call on this object, I need to put code around it that blocks the form.

That's going to be fun.


Lastly how would you suggest blocking the users input during this time?

Setting the active form's enabled to false? That causes the form to draw greyed out.

Override any of the WndProc crap to just ignore incoming messages?

Call on User32 dll to turn off user input for this application (is there not an existing .Net utility for doing this?)?

This post has been edited by lordofduct: 10 July 2013 - 02:43 PM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: WinForms app, gui thread blocked, clicking around causes error.

Posted 10 July 2013 - 02:51 PM

Had you considered doing this as WPF under the MVVM model? That keeps the GUI on its own thread and properly separates the work and data from the UIX.
Was This Post Helpful? 0
  • +
  • -

#5 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2538
  • View blog
  • Posts: 4,641
  • Joined: 24-September 10

Re: WinForms app, gui thread blocked, clicking around causes error.

Posted 10 July 2013 - 02:53 PM

Can't be done.

Product has already been deployed for a few years, and it's not small. Furthermore, it's 1 of multiple other products, one of which gets the most of my attention because it's an even LARGER piece of software that's going thru a conversion from vb6 to vb.net (so big that it ran out of 'namespace' in the vb6 runtime). And actually this issue will also effect this larger project as well, since it's also being done in WinForms (I don't have control over that choice).

Lastly, it's not that I don't want it on the gui thread. I want the gui to block in this time, I want the user to NOT be able to interact during communication to the server. They can't be allowed to perform other tasks while waiting for a response.

This isn't a problem 99.9% of the time, because the response tends to come back almost immediately.

But if the network hiccups (for instance their internet goes down and they're communicating over a VPN on the internet), we have this timeout period, during which impatience results in a less than pretty warning from Windows. The people in my office who decide how the user experience is wants a 'prettier' message box... which there is one that appears if the person hadn't been clicking all over the place like a mad man.



Thankfully this isn't a problem that needs to be remedied immediately. I've already told everyone they'll have to wait, the current way it operates is fine as it seldom happens and usually only happens in a scenario where the application will have to be closed anyway. It's just ugly currently how it stops. When I come up with a fix, I'll fix it.

Thus, discussion here.

This post has been edited by lordofduct: 10 July 2013 - 03:01 PM

Was This Post Helpful? 0
  • +
  • -

#6 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 29
  • View blog
  • Posts: 359
  • Joined: 27-April 08

Re: WinForms app, gui thread blocked, clicking around causes error.

Posted 26 September 2013 - 07:54 AM

If your not making the network calls asynchronously then I am not sure what you can do.

Even the VB6-esque Application.DoEvents() won't help you if the method call that experiences the delay is a blocking method - not that I think Application.DoEvents() is a good way to go, but for me it's that or moving to a task/new thread.

In simple terms the application isn't responding to windows messaging requests asking if it's responding (hence why after a few click's it will likely gray out and say Not Responding) - you would need to stop this by adding a thread or using Application.DoEvents() and then additionally prevent interaction with the form. This can be done quite simply by just setting the form Enabled property to False until the action is complete.

EDIT: After re-reading your response I can see your problem about having to wrap a lot of entry points to server communication... without knowing more about the design I'm not sure how/if you can get away from this...

This post has been edited by danny_kay1710: 26 September 2013 - 07:57 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1