Monday, July 12, 2010

How can I update my user interface from a thread that did not create it?

I had to do this for a test app... Did a long time ago for a production app and need to reference the code.. so here is the link..

Friday, March 19, 2010

Getting data from HTML

I had this issue on an old project.

The problem was how do I pull data from html easily. I found a tool on the gotdotnet website to do this. You can now find it here http://code.msdn.microsoft.com/SgmlReader.

This takes in html and outputs valid xml. Now all you have to do is work with xml.

Simple enough.

Monday, March 8, 2010

Easy way to scale images

Goal: A bucket full of images from Bike week to upload to Flikr.

Issue: Images are to big to upload.

Solution 1: edit each pic manually.

Solution 2: script scaling.

I went with Solution 2.
  1. Installed Imagemagick ( exe
  2. I have cygwin to script, you'll need it.
  3. create script in directory with images:
  4. Run script.
Script:
#!/bin/bash

for i in `ls *.JPG`;
do
n=`echo $i| awk -F "." '{print $1"a."$2}'`
echo $n
/cygdrive/c/Program\ Files/ImageMagick-XXXX/convert.exe $i -scale 800x600 $n
done


That is it. This will convert all JPG files in directory to 800 x 600, creating a copy with an 'a' in the name.

You are welcome. :)

Monday, March 1, 2010

AJAX JSON Information Fetch


Need a web page which fetches information given some arguments from a web service? here you go.

  • Web Service reference 
  • JavaScript
  • Web Service

Address:
City:
State:
Zip:

Friday, February 5, 2010

IE + Flash + SSL = $%$#%@

Found out that if you want to server up images in a secured Flash application in IE, is a pain. Firefox and Chrome no issue.

After searching, yes google, found a link to this Microsoft KB. http://support.microsoft.com/default.aspx?scid=kb;en-us;316431
It says that "The problem occurs if the server is using Secure Sockets Layer (SSL) and has added one or both of the following HTTP headers to the response message:"
This speaks about office documents, but also applies to active x objects, ie Flash.



So, if you response header is returning any of the following, will cause issues.

Pragma: no-cache Cache-control: no-cache,max-age=0,must-revalidate, no-store
You can see this in Fiddler ( you have to check decrypt ssl).

Solution:

Check you web.config make sure you are not caching anything. This sucks for server performance, but will allow the application to work. We also found out that Flash will utilize IE's caching, which benifits the user.

If you still see any of the above in the response header, check the server. IIS has caching settings, clear these out.

After all this is done, the application will server images in Flash, in IE over SSL.

The upseting thing, Microsoft says that "This behavior is by design."

At least I learned something new.

Wednesday, February 3, 2010

Create App Pools via Command Line

You can create app pools via cmd line.

1. Run cmd as Administrator:

2. Change to inetsrv dir.

3. Run a cmd like this:

C:\Windows\System32\inetsrv>appcmd add apppool /name:NewAppPool

(replace "NewAppPool" with what ever you want)

Done.


ref:http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe/

Tuesday, January 26, 2010

Throttling the Internet

This is very useful for seeing how a user will experience your site or web application.
Found out you can do this in Fiddler (http://www.fiddler2.com/fiddler2/).

To enable this you
  1. Click 'Rules'
  2. Click 'Performance'
  3. Enable 'Simulate Modem speeds'


What this does will download a KB of data and add a delay of 150ms by default. This downloads 10KB of every 1.5 seconds.

You can adjust this. If you want 100KB downloaded every second you need to change this delay setting to 10ms.

To adjust this:
  1. Click 'Rules'
  2. Click 'Customize Rules'

This will allow you to adjust the settings. NOTE: You can change all of fiddler's settings in the that opens, so save a backup of this. Click "Save As", close and reopen.

Find "if (m_SimulateModem)" in this file. The first occurrence will be for the upload delay, the second for the download delay. Changing the second to 'oSession["response-trickle-delay"] = "10"; '. This will deliver approximate speed of 100KB/sec.

Thought this would help.

Monday, January 25, 2010

Error 1001. The specified service has been marked for deletion.

Here's an FYI on deleting a windows service. If you have problems completely removing the service.

And get the error:

Error 1001. The specified service has been marked for deletion.

Make sure you don't the services MMC open.

After I closed the services MMC the service was deleted and I could continue installing again.

Wednesday, January 6, 2010

Updateing TextBox from separete thread

I created a little web form app to send messages to a port. This was threaded and I wanted to update the UI with messages. So I had to use this:


Call :
UpdateSendTextBox(pmsData);

Code:
public void UpdateSendTextBox(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action(UpdateSendTextBox), new object[] { value });
return; // important to return in a recursive call.
}
if(!sendingTextBox.IsDisposed) // will not update if application is closing
sendingTextBox.Text = value;
}

It will recursively call the UpdateSendTextBox with a new ui thread to update. That's it.

Life is good.