Skip to content

@chaliy /non_blocking_api_dot_net.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Node.NET: Non blocking API .NET
using System;
using System.IO;
using System.Net;
using System.Security.AccessControl;
using System.Text;
namespace SimpleExample
{
class Program
{
private const int BUFFER_SIZE = 10000;
static void Main(string[] args)
{
// So we need to read file in non blocking way,
// request some stuff from google and exit..
var file = new FileStream("Program.cs", FileMode.Open, FileAccess.Read,
FileShare.None, BUFFER_SIZE, true);
var buffer = new byte[BUFFER_SIZE];
file.BeginRead(buffer, 0, BUFFER_SIZE,
r =>
{
var read = file.EndRead(r);
var stuff = Encoding.Default.GetString(buffer, 0, read);
Console.WriteLine(stuff);
file.Close();
// Lets go futher... lets load some stuff from web
var url = "http://www.google.com/search?q=node.js";
var req = WebRequest.Create(url);
req.BeginGetResponse(
r2 =>
{
var resp = req.EndGetResponse(r2);
Console.WriteLine("{0} headers recieved.",
resp.Headers.Count);
}, null);
}, null);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.