Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finally code
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00970841
Message ID:
00970856
Views:
17
Stephane,
Thanks for the tip, I will look into that tomorrow (I didn't bring my laptop home tonight). On the other hand it is not really that much extra work to have a finally block since I will need to have a try..catch around creating the socket, connecting and sending anyways.

Einar

>What you could do if the Socket class suports IDisposable is use a using statement, that way, you don't have to worry about writing a finnally block, the Scocket object will dispose itself.
>
>
>using (Socket udpSocket = new Socket(ipEP.Address.AddressFamily,SocketType.Dgram,ProtocolType.Udp))
>{
>	// some more code				
>}
>
>
>
>HTH
>>I can not remember the exact syntax for what I want to do, but I am sure this is used all over the place.
>>Considder the code:
>>
>>try
>>{
>>  // some code
>>  IPEndPoint ipEP = new IPEndPoint(paraIPAddress, iPort);
>>  Socket udpSocket = new Socket(ipEP.Address.AddressFamily,SocketType.Dgram,ProtocolType.Udp);
>>  // some more code
>>}
>>catch(Exception ex)
>>{
>>  //Do something if exception is thrown
>>}
>>finally
>>{
>>  //I need some code here to test if the socket is created/initialized
>>  udpSocket.Close();
>>}
>>
>>
>>The contents of the code is not really important, but what can I use in the finally block to ensure that the object that I am trying to call the "clean-up" code for (in this case Close()) has been initialized? What if an error was thrown before the line Socket udpSocket = new Socket(...), I want to call Close() on the udpSocket in the finally block but only if the object udpSocket is defined.
>>
>>Thanks,
>>Einar
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform