The ramblings of a disgruntled geek!!
Wednesday, June 24, 2009
Reporting issues with Windows Azure
http://social.msdn.microsoft.com/Forums/en-US/windowsazure/threads/
Steps you need to follow:
1. Sign into Windows Azure portal.
2. Go to your Hosted Service Project which is causing issues.
3. Wait for the project info to load.
4. Copy the private deployment id.
5. Write a brief description of what you did, what you are seeing and add your private deployment id.
Here is a screen shot of my service showing the private deployment id.
Tuesday, March 03, 2009
ThreadStaticAttribute
Reminder to self:
ThreadStaticAttribute only works with static fields!
Here is why:
public class TestingTLS
{
[ThreadStatic]
public static int value = 0;
[ThreadStatic]
public int value2 = 0;
}
public class MyClass
{
public static void TLSTest()
{
TestingTLS tls = new TestingTLS();
Dictionary<int, Thread> threads = new Dictionary<int, Thread>();
Semaphore sem = new Semaphore(100, 100);
long count = 0;
for ( int i = 0 ; i < 100 ; i ++ )
{
Thread t = new Thread(state => {
int tid = Thread.CurrentThread.ManagedThreadId;
TestingTLS.value = tid;
Thread.Sleep(0);
if ( tid != TestingTLS.value )
{
Console.Error.WriteLine( "Value 1: {0} read {1}", tid, TestingTLS.value );
Interlocked.Increment(ref count);
}
tls.value2 = tid;
Thread.Sleep(0);
if ( tid != tls.value2 )
{
Console.Error.WriteLine( "Value 2: {0} read {1}", tid, tls.value2);
Interlocked.Increment(ref count);
}
threads.Remove(tid);
if ( threads.Count == 0 )
sem.Release();
});
threads.Add(t.ManagedThreadId, t);
sem.WaitOne();
t.Start();
}
Console.WriteLine("Waiting for all threads to finish...");
sem.WaitOne();
Console.WriteLine("Total races: " + count);
}
}
You will see races for value2 but not for value.
Update: The code snippet was updated, since the previous example had a race where the Total Race count would reach before all threads have finished reporting the wrong number of total races in cases where there were large number of races.
Wednesday, January 28, 2009
First Azure Service is live!
This is my first Azure service that I wrote a couple of weeks ago. It only uses the front end roles and no storage. I will add other applications to this portal, which will use other services offered by Azure.
XmlTextReader fiasco
I hit a snag a few days ago while doing some Xml parsing in one of my applications.
I am using XDocument for Xml parsing(XLinq is beautiful (K)).
Doing XDocument.Load(urlString) or XmlTextReader(
Code Snippet (fails):
WebRequest req = WebRequest.Create("
WebResponse res = req.GetResponse();
XmlTextReader reader = new XmlTextReader(res.GetResponseStream());
XDocument xdoc = XDocument.Load(reader, LoadOptions.SetLineInfo); //LoadOptions.SetLineInfo helps with debugging.
Code Snippet (works):
WebRequest req = WebRequest.Create("
WebResponse res = req.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
XDocument xdoc = XDocument.Load(reader, LoadOptions.SetLineInfo); //LoadOptions.SetLineInfo helps with debugging.
Happy XLinq-ing.