Re: multithreaded tcp/ip monitoring application



On Tue, 10 Jul 2007 12:48:02 -0700, Punit Kaur <PunitKaur@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Also I was using Sleep for 3 seconds and Application.DoEvents() because I ws
trying to update a labels text and it was not updating it. After I added
Doevents, it got updated.

Sleeping for three seconds did not do anything to change the updating, other than to make the user wait arbitrarily for three seconds before the connection could proceed. As for calling DoEvents(), yes...that allows the UI to update itself.

But a) it is "better" in that situation to simply call Control.Update() on the control you've changed, and b) it is even better to not have the main UI thread block in the first place (for example, doing a synchronous call to TcpClient.Connect()). If you use the mechanisms I am suggesting here, your change to the text label will be displayed nearly as soon as it's been made in your code, and will not be delayed by the time it takes to successfully complete the TCP connection.

Note that in reality, calling Control.Update() or Control.Refresh() is usually almost as bad as calling DoEvents(). Any of those methods is frequently an indication of a design problem, since they are almost never actually required.

And I added sleep so that that text " Trying to establish Connection" remain
for sometime.. to show the user that the connection to the remote application
was being made. Just wanted it to be a little fancy. Any better suggestion to
implement this?

Implement the TcpClient stuff using the Begin/EndXXX mechanism, and everything else will work fine.

Also, I will point out that I see to usefulness in putting a Sleep() in your code just so the user can see some particular text you've set. If the text would otherwise be immediately changed to reflect a successful connection, what point is there in wasting three seconds telling the user that you are _trying_ to establish the connection.

For one thing, during the three seconds you're sitting there, you're not actually trying to establish the connection. So you're lying to the user. For another, if the connection completes so quickly that the user never sees the phrase "Trying to establish connection", so what? Presumably the next phrase will be "Connection established" or something like that, which implies to the user that you did in fact try to establish the connection.

Don't put arbitrary delays into your code. They just waste the user's time.

Pete
.



Relevant Pages

  • Re: Merge introduces 0 instead of house number
    ... Try changing the method of connection to the data source to DDE. ... I create new excel documents then use them to print labels in ... addresses suffer from the house number being replaced by a zero. ...
    (microsoft.public.word.mailmerge.fields)
  • trouble with cvsup
    ... Server software version: SNAP_16_1h ... Establishing multiplexed-mode data connection ... backup of my kernel conf file in there, ... and got the updating error again. ...
    (freebsd-questions)
  • Re: Update not working
    ... // Mark the changes for updating ... connection, process request, break connection ... DataSet dataSet = new DataSet; ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Update not working
    ... // Mark the changes for updating ... connection, process request, break connection ... DataSet dataSet = new DataSet; ...
    (microsoft.public.dotnet.framework.adonet)
  • (no subject)
    ... Server software version: SNAP_16_1h ... Establishing multiplexed-mode data connection ... backup of my kernel conf file in there, ... and got the updating error again. ...
    (freebsd-questions)

Loading