18 December 2006

Visual Studo 2005 SP1 is here

Today I tried to install Visual Studo 2005 SP1 and had some setup issues.
I hope this guide will help you as a reference of what to do:
1) Remove SP beta - Activate show updates in add-remove programs.
Don't forget to have your original VS.Net installation medium available!!!
2) Unistall the Web Application Project, since it is built-in to SP1
3) The following error is normal:
The installation of C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ZNW442\VS80sp1-KB926601-X86-ENU.msp is not permitted due to an error in software restriction policy processing. The object cannot be trusted.
A workaround:
i) Open Administrative Tools
ii) Open Local Security Policy
iii) Select Software Restriction Policies
iv) If no software restrictions are defined, right click the Software Restriction Policies node and select New Software Restriction Policy
v) Double click Enforcement and select "All users except local administrators"
vi) Click OK
vii) Reboot the machine

More information on Heath Stewart's Blog
To learn more about Visual Studio SP1 visit Development Catharsis

Unobtrusive Flash Objects (UFO)

Unobtrusive Flash Objects (UFO) is a DOM script that embeds the Flash object and resolves the flash activation problem.
UFO is free and supports the W3C standards.

Example:

<html>
<head>
<script src="ufo.js" type="text/javascript"></script>
<script type="text/javascript">
var FO = { movie:"FlashMovie.swf", width:"200", height:"100",
majorversion:"6", build:"40" };
UFO.create(FO, "FlashLayer");
</script>
</head>
<body>
<div id="FlashLayer">
<p>Alternate Content


</div>
</body>
</html>

More information and dowload here.

How to place flash on back of HTML?

To place flash on back of HTML, set the flash container with z-index to -1:
<div id="flashContent" style="z-index:-1" ></div>

and set flash variable wmode to opaque.

06 October 2006

How to fix: Version mismatch. BAML stream has version number '0.96' but parser can read only version '0.94'.

After you uninstall .Net 3.0 runtime, windows sdk and orcas, you ran the uninstall utility, which should work in most cases. If it does not, uninstall everything again and run the uninstall utility again.

After all this, reboot and check folder C:\Program Files\Reference Assemblies\Microsoft. If there are any folders or files in this folder, then manually removed them. After you restart your PC; only install the .Net 3.0 Runtime. Verify that it works first before proceeding with the install of the SDK and Orcas. You should be able to verify that the runtime is installed correctly if you go to http://xaml.net/ and click on the Snowboarder image. The image will load a xaml page with an animated snowboarder. If this works, proceed with the install of SDK and Ocras.

02 August 2006

Convert a string to TimeSpan

How to Convert a string to TimeSpan in C#


To convert a string with hours, minutes and seconds to a time span, use:

TimeSpan.Parse("00:30:00");

Microsoft Message Queue in C#

How to read/write to a Message Queue in c#:

Write:
MessageQueue queue = null;
if (context.Cache["QueueKey"] == null)
{
queue = new MessageQueue(".\private$\queueName", false, true);
context.Cache["QueueKey"] = queue;
}
else
{
queue = (MessageQueue)context.Cache["QueueKey"];
}
queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(System.String) });
queue.Send(msg);

Read using a windows service:
public partial class QueueService : ServiceBase
{
int _threadCount= 5;
TimeSpan _joinThreadsTimeSpan = TimeSpan.Parse("00:00:02");

Thread[] workerThreads;
QueueReader[] threadHandlers;

public QueueService ()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
arrWorkers = new QueueReader[_threadCount];
threadHandlers = new Thread[_numberOfThreads];

for (int i = 0; i < _threadCount; i++)
{
threadHandlers[i] = new QueueReader();
threadHandlers[i].ServiceStarted = true;

ThreadStart st = new ThreadStart(threadHandlers[i].ExecuteTask);
workerThreads[i] = new Thread(st);
}

for (int i = 0; i < _threadCount; i++)
{
workerThreads[i].Start();
}
}

protected override void OnStop()
{
for (int i = 0; i < _threadCount; i++)
{
threadHandlers[i].ServiceStarted = false;
workerThreads[i].Join(_joinThreadsTimeSpan);
}
}
}

QueueReader Threads
public class QueueReader
{
private MessageQueue _queue = null;
private TimeSpan _timeToWait = TimeSpan.Parse("00:00:05");
private bool _serviceStarted = false;

public QueueReader()
{

_queue = new MessageQueue(".\private$\queueName");
_queue.ReceiveCompleted += new ReceiveCompletedEventHandler(OnReceiveCompleted);
_queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(System.String) });
_queue.BeginReceive(_timeToWait);
}


public bool ServiceStarted
{
get
{
return _serviceStarted;
}
set
{
_serviceStarted = value;
}
}

public void ExecuteTask()
{
while (_serviceStarted)
{
Thread.Sleep(_timeToWait);
}

Thread.CurrentThread.Abort();
}


private void OnReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
MessageQueue senderQueue = null;

try
{
senderQueue = (MessageQueue)sender;

Message message = senderQueue.EndReceive(e.AsyncResult);


}
catch (MessageQueueException)
{
}
catch (Exception ex)
{
throw(ex);
}
finally
{
_queue.BeginReceive(_timeToWait);
}
}
}