Binary Artist

The Jason Marshall Experience

Binary Artist

Jason Marshall
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Using Namespace Alias Qualifier (C# Programming Guide)

 

The ability to access a member in the global namespace is useful when

the member might be hidden by another entity of the same name.

In this example, the namespace System is used to include the class TestClass therefore, global::System.Console must be used to reference the System.Console class, which is hidden by the System namespace. Also, the alias mcLovin is used to refer to the namespace System.Collections; therefore, the instance of a System.Collections..::.Hashtable was created using this alias instead of the namespace.

  

Posted by Admin on Wednesday, April 30, 2008 8:37 AM
Permalink | Comments (0) | Post RSSRSS comment feed

When Multi threading unsafe COM Win32 code always specify a seperate apartment model

A .NET thread is automatically assigned an apartment upon entering apartment-savvy Win32 or legacy COM code. By default, it will be allocated a multi-threaded apartment, unless one requests a single-threaded apartment as follows:
 Image Preview
Thread t = new Thread (...);
t.SetApartmentState (ApartmentState.STA);
One can also request that the main thread join a single-threaded apartment using the STAThread attribute on the main method:
class Program {
  [STAThread]
  static void Main() {
  ...
Apartments have no effect while executing pure .NET code. In other words, two threads with an apartment state of STA can simultaneously call the same method on the same object, and no automatic marshalling or locking will take place. Only when execution hits unmanaged code can they kick in.The types in the System.Windows.Forms namespace extensively call Win32 code designed to work in a single-threaded apartment. For this reason, a Windows Forms program should have have the [STAThread] attribute on its main method, otherwise one of two things will occur upon reaching Win32 UI code:
  • it will marshal over to a single-threaded apartment
  • it will crumble and fail.

Posted by Admin on Wednesday, April 30, 2008 4:29 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Who wrote this piece of code ?

Don't complain about BAD code you come across, Just fix it. Usually you are not privy to the exact situation surrounding the code you see before you.

It's easy to criticize older code someone else has written, but we have all written code that could be better. 

Ever come across a section of code, and say to your self... "Whoa! This sucks!” I wonder what the developer was thinking here.
Then you look further down and realize you wrote it 2 years ago late at night when you had the flu.
 
  

    + =

You can almost always refactor your code to make it more streamlined, readable and efficient.  But not everyone has the time, or makes time to do so.
The important message here is to "Just fix it " but be carefull there could be good reasons for the decisions made to code this solutiuon in a particular way.

More to come...


Categories: C# | LINQ | SQL Server | XNA
Posted by Admin on Tuesday, April 29, 2008 3:10 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Over Engineering Software Design

Need more cow bells ?

 Over engineering your software application is when you attempt to make it so flexible or scalable that you lose focus on returning business value. Often you can get swept up in programming and designing just for the sake of doing so.  It’s so tempting to use that “New” technology to tackle any problem that comes your way with a cool design pattern or “the tool of the month”.  Some programmers attempt to make their software very flexible and sophisticated because they believe they know their system’s future requirements.  In there programmer minds they reason that it's best to make a design more flexible or sophisticated, so it can accommodate the needs of tomorrow. This is perfect if you have a crystal ball or are psychic.  Ok you may be saying…”Yeah but based on my experience, I believe I have a handle on this business domain enough to predict the future of this software development.”


Ok, but what if you're wrong ?... If your predictions are wrong, you waste precious time, resources and money.  Then you and your team will spend days or even weeks tweaking an overly complex “flexible” piece of code.  This is time you could have spent writing the new logic exactly the way it should be to provide business value.

 

Except for the guys that work at a R&D software think-tank most of us have a business need that drives our software development, which in turn drives our paychecks.

To turn your back on business value is to bite the hand that feeds you.

 

 


Tags:
Categories: C# | LINQ
Posted by Admin on Monday, April 28, 2008 9:25 AM
Permalink | Comments (0) | Post RSSRSS comment feed

What would you say... ya do here?

Remember middle managment needs to look important also !!!


Posted by Admin on Monday, April 28, 2008 8:01 AM
Permalink | Comments (0) | Post RSSRSS comment feed

LINQ with Transactions

 This is a simple example of how to wrap your LINQ db.DataContext SubmitChanges() in a Transaction.

This is much like using transaction in SQL Server.

I used a simple add function to outline the pattern to use when wrapping your LINQ commits in transactions.

*Add a ref to System.Transactions;

 

 

  
  
New LINQ the home verion. now you and your friends can play "Map that Relational Object" on a Friday Night !!!

* Some assembily required.

   (database not included)

 

 

  using System.Transactions;


Categories: C# | LINQ
Posted by Admin on Thursday, April 17, 2008 9:30 AM
Permalink | Comments (0) | Post RSSRSS comment feed
Free Hit Counters
page counter