Asynchronous Programming with Async and Await (C# and Visual Basic)

Posted by & filed under .Net, Programming.

Looks like async development got a whole lot easier in .Net 4.5:


Visual Studio 2012 introduces a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and the Windows Runtime. The compiler does the difficult work that the developer used to do, and your application retains a logical structure that resembles synchronous code. As a result, you get all the advantages of asynchronous programming with a fraction of the effort.

This topic contains the following sections.


Snowstorm Success

Posted by & filed under .Net, Gaming, Programming.

We have a snowstorm!

After fixing some problems with my collision detection system, I got it working! It’s rough, but some added work on the physics side, and more tuning and it will be even sweeter! – POSTing multipart/form-data

Posted by & filed under .Net, Programming.

Today I needed to be able to POST multipart/form-data to a form in order to submit for values as well as upload a file. All using HTTP POST.

The first step was finding out that there does not seem to be a native way to post both form parameter and upload a file together. WebClient.UploadValues allows for the parameter name/value pairs, but sets it’s encoding type to application/x-www-form-urlencoded which is incorrect for file uploads. The code for this would look something like this:

Dim data As New NameValueCollection();
data.Add("id", "10")
data.Add("param", "content")
data.Add("file", "A0BA")
Dim client As New WebClient
client.UploadValues("", null, data)

I found that WebClient.UploadFile does set content type to multipart/form-data, *BUT* there is no way to post parameters, and the request is not properly formatted. To clarify, it will work fine with a IIS webserver, but any other real webserver (Apache, Tomcat) would choke on the malformed output. Microsoft does not do standards too well if you have not noticed. Microsoft — if you are reading this, kindly go read RFC1867. The call would look like this

Dim client As New WebClient
client.UploadFile("", null, "c:\test.txt");

My main issue is not the incompatibility in this instance, but rather that I cannot post parameters and the file in the same post.

In order to solve this, I found a excellent class written by Gregory Prentice. I compiled the c# class and included a reference to it in my app. Then it was a simple matter of adding the reference Imports Helpers and adding this code:

Dim form As New MultipartForm("")
form.SetField("id", "10")
form.SetField("param", "content")

And booyah it works!

Additional Link Dump:
Uploading a file over HTTP in .NET
Three ways to use C# within a VB.NET project
System.Net.WebClient Class
How to post a file via HTTP post in
Upload files with HTTPWebrequest (multipart/form-data)

Finished my first real .Net app today…

Posted by & filed under .Net, Programming, Windows.

I finished a sweet .net app today. It’s which is kinda gay I guess but it gets the job done and is a lot better than the VB I knew long ago. The app itself spawns a new process and runs a netsh command extracting/grepping out the info needed.

I’m headed to PRI tomorrow. Tired and should of already been sleeping. damn black ops.