Re: C# Multithreading

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: jimirwin (USERjimirwin_at_DOMAINholoscenes.org)
Date: 06/01/04


Date: Tue, 01 Jun 2004 23:28:32 GMT

Michael C wrote in microsoft.public.dotnet.framework.interop:

>... For some servers it takes up to 10 seconds to get a
>response, and locking up the UI/not returning a response for 700 secs is
>not an option. I'm trying to use an array of WaitHandle objects to wait
>until all the methods are complete, but I think I may be stuck with the
>700 sec delay again. Is there a way to call the function that requests
>server info 70 times, each on separate threads and gather/use the
>results as each thread completes? Can anyone point me in the right
>direction?

The approach I might take would be to set up a worker thread to make the
calls, and keep the user out of trouble with an application modal progress
dialog that cannot be closed until all the servers have responded or timed
out (or the user cancels the operation). Presumbably the user has
requested this poll directly or indirectly though some action, so they
might expect and accept some wait?

You can still use async delegates as your worker threads -- let each
callback function send a message to the progress dialog; when the dialog
detects that all the callback messages have been received, it closes.
Depending on how many delegates you let loose at one time, and how many
threads the runtime has available in the pool, you should be able to cut
down the wait substantially.

If a progress dialog is unacceptable and the user has to be allowed to do
other things in your application while the poll is in progress, then I
would definitely set up a separate worker thread, and have that thread send
a message to your main thread when it completes the polling. Once you
start a poll, you would want to disable any menu items or widgets that
might allow the user to trigger another concurrent poll.

-- 
Jim Irwin
http://www.holoscenes.com


Relevant Pages

  • They are spining on the part of the interview now, wont appoint dancers later.
    ... grocer up to the convincing universe is the wealth that excuses ... inhibits in response to tan, ... sink is too turkish for Clint to progress it. ... past circle. ...
    (sci.crypt)
  • Re: New poll shows americans feel race was a factor
    ... This poll shows the american people are actually pretty smart. ... FIFTY-SEVEN PERCENT OF AMERICANS HAVE LOST CONFIDENCE IN GOVERNMENT TO DEAL WITH ANOTHER NATURAL DISASTER; 52% DO NOT TRUST PRESIDENT TO MAKE RIGHT DECISIONS IN A CRISIS ... In addition, 57 percent of Americans say the slow response in New Orleans has caused them to lose confidence in the government to deal with another major natural disaster, 41 percent say it has not; 47 percent say it has made them lose confidence in government to prevent another 9/11-type attack; half say it has not, the poll shows. ...
    (rec.music.dylan)
  • Re: MFC and threads
    ... the response or a quit request. ... and I don't have to convert my worker thread into ... transform the following worker thread pseudocode into your ... I typically use this when I am doing I/O to a 'device' which may have to eg maintain 'keep alive' messages but also respond to messages to be sent from the mainline and to assemble messages and send them to the mainline. ...
    (microsoft.public.vc.mfc)
  • Re: implementing a time bound wait on the socket (TCP)
    ... Poll() method isn't reliable (the Socket may become unreasonable between   ... The ongoing design on the client side is not in ... a response in a byte buffer (there are no intentional delays on the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Bush vs. Clinton in the polls: (was OT: 43 at 29
    ... Bush's poll numbers started to deteriorate after Hurricane Katrina, ... I am not saying that I think the primary fault for the Katrina response ... disaster lies with the Feds or the Bush Administration in particular (I ...
    (rec.music.classical.recordings)