Sunday, October 7, 2007

Boo - Asynchronous call

import System
import System.Collections
import System.Threading
import System.Net

def callback(result as IAsyncResult):
    print("callback")
    
def run():
    print "Executing"
    
print("started")

result = run.BeginInvoke(callback, null)
System.Threading.Thread.Sleep(50ms)
run.EndInvoke(result)

print ("done")

request = WebRequest.Create("http://www.python.org/")

result = request.GetResponse.BeginInvoke(null, null)
while not result.IsCompleted:
    Console.Write("!")
    Thread.Sleep(25ms)
Console.WriteLine()

// ready to get the response
response = request.GetResponse.EndInvoke(result)

Console.WriteLine("${response.ContentLength} bytes.")

print "Press any key to continue . . . "
Console.ReadKey(true)

Boo and WMI

namespace wmi

import System
import System.Management
import System.Collections

query =  """SELECT * FROM Win32_LogicalDisk  
            where drivetype=3"""

searcher = ManagementObjectSearcher("root\\CIMV2",query)
results = searcher.Get()

for b as ManagementObject in results:
    print b.Properties["DeviceID"].Value,b.Properties["Size"].Value

print "Press any key to continue . . . "
Console.ReadKey(true)