473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

C# run another socket connect before the first call finish

123 100+
I write a socket connect function, I would like to have 2 button for 2 different connection, once the first IP/port is scanning, I can click another button to start the second IP/port scan, however, it looks like C# always need to wait until the first call to finish.

Expand|Select|Wrap|Line Numbers
  1. Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  2.  
  3. // Connect using a timeout (5 seconds)
  4.  
  5. label2.Text="Connecting...";
  6. IAsyncResult result = socket.BeginConnect( sIP, iPort, null, null );
  7.  
  8. bool success = result.AsyncWaitHandle.WaitOne( 5000, true );
  9.  
  10. if ( !success )
  11. {
  12.             // NOTE, MUST CLOSE THE SOCKET
  13.  
  14.             socket.Close();
  15.             label2.Text="Connect failed"; 
  16. } else {
  17.             label2.Text="Connect successfully.";
  18. }
  19.  
Mar 4 '12 #1
0 1233

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: d2bishop | last post by:
Hi, I am programmatically setting the .Text property of a number of Labels on my Windows form at runtime, but I am experiencing some very strange behaviour when I do this. The code I am using...
2
by: xzzy | last post by:
I have an app that uses a listbox to display program status messages, and a public function to be used by the solution to update the listbox. I do not know how to make the listbox public so it...
1
by: Marc Chouteau | last post by:
How to change the display of status bar with the "LinkButton" control ? for example : javascript:__doPostback() Marc
0
by: Stephen D. Carlton | last post by:
Is there a way I can display my online status for MSN or Windows messenger the way I can for Yahoo, AOL and ICQ? This should be such a difficult or odd request but I can't seem to find an example...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
0
by: doc | last post by:
Hi Hard to know where to post this and I don't want to double post it - please move it if you need to, I am trying to connect a Flash client socket (XML) to a php socket server (using Flash 8 and...
0
by: veenna | last post by:
I have one label in template coloumn of datagrid ,i want to apply backcolor to the label according to the color selected from database as(Red,Blue)etc . how to bind color field to this label...
1
by: K Viltersten | last post by:
> bar.PerformStep (); I noticed that there's a property for the bar stating what time it should take for the animation to move the fill to the requested spot. I'm guessing that's the time i...
2
by: jay123 | last post by:
Hello, I am making a project in VS2008, C#. Background of prob: I have integrated a postcode(UK- its like if someone enters postcode and clicks button to retrieve the address, he gets all the...
9
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.