Monday, January 4, 2010

Silverlight WCF Proxy Close

Hi, I just wanted to let you all know that I believe it is advantageous to close your proxies when leaving a silverlight page. The best way, I believe, is to do this in the class destructor.

~MainPage()
{
if (proxy != null)
{
proxy.CloseAsync();
proxy = null;
}
}

Hope this helps someone.

Monday, December 14, 2009

How to Access an Access Database from GoDaddy

Here's a way I found useful for accessing an access database in code from GoDaddy, Hope it helps someone.

First Include:
System.Web

private static string GetConnectionString()
{
HttpContext serverContext = System.Web.HttpContext.Current;

string db_path = string.Empty;
string db_dir = serverContext.Server.MapPath("access_db") + "\\";
db_path = db_dir + "Crossroads.mdb";
string connectstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + db_path;
return connectstr;
}

Sunday, December 28, 2008

Microsoft's bizspark program

I decided to try and use the program by Microsoft called Bizspark http://www.microsoftstartupzone.com/. It's basically a way for you to get your name out there with your business idea. It's also an incentive to get your idea off the ground. Some of the great benefits you get by signing up are free access to Microsoft Development tools and free webspace to try out your asp.net ideas. There are some strings attached to signing up though:

1. You must pay Microsoft a $100 fee after three years.
2. You must not have had an operating business with your idea (startups only).
3. You must be in the business of developing software.
4. You must be private
5. You must have < 1M in annual revenue (not a problem in my case)

Also, you have to find a sponsor before you can enroll. If you are interested in enrolling you will be presented with a list of available businesses on the enrollment page willing to help sponsor along with their contact email address.

Check it out and Good Luck!

Friday, November 7, 2008

Writing a thread-safe console log

A few days ago, I ran into the problem of how to display logging or status info in the user interface when the log messages are generated in a different thread. I found a result that seems to work satisfactorily at the moment.

I'm going to give the example in VB .NET but it will work easily in C# also.

First off, create a simple delegate:
Public Delegate Sub LogSafeCall(ByVal s As String)

Then create a Sub to provide thread safety. I will use a listbox in this example but you could also use a textbox. The reason for choosing the listbox is due to the fact that it stores strings in a collection. A textbox would require appending to the text property, and...since strings are immutable, this would create many seperate strings in memory.

Here's the Threadsafe logging function, m_console is a listbox control:
Private Sub Log(ByVal s As String)
If (m_console.InvokeRequired) Then
Dim d As LogSafeCall = New LogSafeCall(AddressOf Log)
m_console.Invoke(d, s)
Else
m_console.Items.Add(s)
'if you wish to have the last item selected then uncomment the following:
'm_console.SelectedIndex = m_console.Items.Count - 1
End If
End Sub


Since I wanted to Log in a file as well as display the messages into the textbox, I created the following class and inherited the TextWriter streaming class So here is the complete code:

Option Explicit On
Option Strict On
Imports System.IO
Imports System.Windows.Forms

Public Delegate Sub LogSafeCall(ByVal s As String)
Public Class ListBoxWriter
Inherits TextWriter
Private m_console As ListBox
Public Sub New(ByVal console As ListBox)
m_console = console
End Sub
Public Overrides ReadOnly Property Encoding() As System.Text.Encoding
Get
Return System.Text.Encoding.ASCII
End Get
End Property

Public Overrides Sub WriteLine(ByVal value As String)
MyBase.WriteLine(value)
Log(value)
End Sub

Private Sub Log(ByVal s As String)
If (m_console.InvokeRequired) Then
Dim d As LogSafeCall = New LogSafeCall(AddressOf Log)
m_console.Invoke(d, s)
Else
m_console.Items.Add(s)
'm_console.SelectedIndex = m_console.Items.Count - 1
End If
End Sub
End Class

Thursday, October 30, 2008

New Dell Laptop XPS M1730

Last week, I bought a Dell Laptop for my road clients. It's an XPS Model 1730 with a whopping 17" screen. I always buy my Dell stuff in the outlet store and this laptop was refurbished. It boasts a dual core 2.8 Ghz Intel CPU, 4 GB Memory and came with Vista Ultimate. I paid around $2k for the system. So far I like it very much, the bootup is very fast and all of my development software installed very nicely. It has one of those fancy new 128 MB solid state drives that the operating system resides on and I guess that's why bootup is so fast. I also have a 360GB standard Seagate drive that I purchased at tiger direct for around $80. I like the screen size very much. This is NOT a good laptop for portability since it weighs a lot and requires a mammoth sized power supply that is about 8 x 4 x 2 inches. It's great for me because I frequently need the power of a desktop without lugging a desktop around in my car. If you are working on a plane or while riding the bus, this probably would not be a good choice. The power drain on the batteries is about 1 hour, perhaps one could get it to two hours by adjusting the power settings. If you require a more portable model, the XPS 15" models are just about the same as this 17" model in power and features, but much more portable and the batteries last longer. My son, Erik, uses a Dell XPS 15 while in college and likes it very much.

Thursday, October 16, 2008

CodeSmith Review

Most of my coding happens to be repetitive. Therefore I'm always thinking there's got a be a way to generate the similar code and rename the classes and various attributes. While I was on David Hayden's site http://www.davidhayden.com/, I saw an ad for Codesmith. After reviewing the features and asking a few folks in the IT world what they thought about it, I decided to give it a try. Instantly I fell in love with it because of it's ease of use and I was instantly productive straight out of the box! Here's some things I was able to do:
Generate Code based on database schema - using included examples
Port my own code into a template for re-use
Generate both VB and C# Code

The possibilities are endless, you can create libraries of code you are confident works and you wish to reuse over and over. There's a handy properties pane similar to the one in Visual Studio that you can use to change the custom properties you define in the template file. Once the template file is written, all that's required is setting a few properties in the properties pane and generating the code.

There's a few videos to help you get started on the Codesmith website http://www.codesmithtools.com/ . I highly recommend the product if you find yourself writing similar code all day. Hey, you can do a days work in 5 minutes once the template is in place! Look good all day while hardly breaking a sweat. It is a bit pricey for those, like me that are buying this themselves for around $400, but worth it in time savings.

Wednesday, October 15, 2008

Seagate 1.5 TB Drive

Yesterday, I received a new Seagate Barracuda 7200.11 1.5TB Hard Drive ST31500341AS - Serial ATA 7200/32MB/SATA-3G. I run a Vista Machine with Dual AMD 3GHZ Processors and ran into problems when creating the partition for this drive. It takes a long time to format/partition the drive, I guess, due to it's size. When the format reached format: 73%, it just hung there all night. I googled on this and found one other person had this problem and it was resolved by enabling the second SATA controller. I don't have a second SATA controller so I ended up formatting it on another machine via a SATA drive enclosure using USB 2. Not quite the resolution I was looking for, but it worked ok. I still would hate to do this again but it worked. I guess sometimes it's whatever works. Why do I have such a large drive you ask? Well, I do a lot of data intensive programming and my 500GB drive is 2/3 full allready!